refactor:Simplified lambda expressions for PriorityQueue in heap.md and heap.java (#379)
This commit is contained in:
parent
a2b74943a2
commit
f2d2cca5f1
@ -28,7 +28,7 @@ public class heap {
|
||||
// 初始化小顶堆
|
||||
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以下测试样例为大顶堆");
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user