Skip to content

Commit

Permalink
refactor:Simplified lambda expressions for PriorityQueue in heap.md a…
Browse files Browse the repository at this point in the history
…nd heap.java (krahets#379)
  • Loading branch information
4yDX3906 authored Feb 22, 2023
1 parent a2b7494 commit f2d2cca
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion codes/java/chapter_heap/heap.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static void main(String[] args) {
// 初始化小顶堆
Queue<Integer> minHeap = new PriorityQueue<>();
// 初始化大顶堆(使用 lambda 表达式修改 Comparator 即可)
Queue<Integer> maxHeap = new PriorityQueue<>((a, b) -> { return b - a; });
Queue<Integer> maxHeap = new PriorityQueue<>((a, b) -> b - a);

System.out.println("\n以下测试样例为大顶堆");

Expand Down
2 changes: 1 addition & 1 deletion docs/chapter_heap/heap.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ comments: true
// 初始化小顶堆
Queue<Integer> minHeap = new PriorityQueue<>();
// 初始化大顶堆(使用 lambda 表达式修改 Comparator 即可)
Queue<Integer> maxHeap = new PriorityQueue<>((a, b) -> { return b - a; });
Queue<Integer> maxHeap = new PriorityQueue<>((a, b) -> b - a);

/* 元素入堆 */
maxHeap.add(1);
Expand Down

0 comments on commit f2d2cca

Please sign in to comment.