mirror of
				https://github.com/krahets/hello-algo.git
				synced 2025-11-04 14:18:20 +08:00 
			
		
		
		
	refactor:Simplified lambda expressions for PriorityQueue in heap.md and heap.java (#379)
This commit is contained in:
		@ -28,7 +28,7 @@ public class heap {
 | 
				
			|||||||
        // 初始化小顶堆
 | 
					        // 初始化小顶堆
 | 
				
			||||||
        Queue<Integer> minHeap = new PriorityQueue<>();
 | 
					        Queue<Integer> minHeap = new PriorityQueue<>();
 | 
				
			||||||
        // 初始化大顶堆(使用 lambda 表达式修改 Comparator 即可)
 | 
					        // 初始化大顶堆(使用 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以下测试样例为大顶堆");
 | 
					        System.out.println("\n以下测试样例为大顶堆");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -52,7 +52,7 @@ comments: true
 | 
				
			|||||||
    // 初始化小顶堆
 | 
					    // 初始化小顶堆
 | 
				
			||||||
    Queue<Integer> minHeap = new PriorityQueue<>();
 | 
					    Queue<Integer> minHeap = new PriorityQueue<>();
 | 
				
			||||||
    // 初始化大顶堆(使用 lambda 表达式修改 Comparator 即可)
 | 
					    // 初始化大顶堆(使用 lambda 表达式修改 Comparator 即可)
 | 
				
			||||||
    Queue<Integer> maxHeap = new PriorityQueue<>((a, b) -> { return b - a; });
 | 
					    Queue<Integer> maxHeap = new PriorityQueue<>((a, b) -> b - a);
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    /* 元素入堆 */
 | 
					    /* 元素入堆 */
 | 
				
			||||||
    maxHeap.add(1);
 | 
					    maxHeap.add(1);
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user