mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 04:31:55 +08:00
refactor: Replace 'poll' with 'pop' in Heap (#416)
This commit is contained in:
@ -18,7 +18,7 @@ public class heap
|
||||
PrintUtil.printHeap(heap);
|
||||
}
|
||||
|
||||
public void testPoll(PriorityQueue<int, int> heap)
|
||||
public void testPop(PriorityQueue<int, int> heap)
|
||||
{
|
||||
int val = heap.Dequeue(); // 堆顶元素出堆
|
||||
Console.WriteLine($"\n堆顶元素 {val} 出堆后\n");
|
||||
@ -47,11 +47,11 @@ public class heap
|
||||
|
||||
/* 堆顶元素出堆 */
|
||||
// 出堆元素会形成一个从大到小的序列
|
||||
testPoll(maxHeap);
|
||||
testPoll(maxHeap);
|
||||
testPoll(maxHeap);
|
||||
testPoll(maxHeap);
|
||||
testPoll(maxHeap);
|
||||
testPop(maxHeap);
|
||||
testPop(maxHeap);
|
||||
testPop(maxHeap);
|
||||
testPop(maxHeap);
|
||||
testPop(maxHeap);
|
||||
|
||||
/* 获取堆大小 */
|
||||
int size = maxHeap.Count;
|
||||
|
||||
@ -97,7 +97,7 @@ class MaxHeap
|
||||
}
|
||||
|
||||
/* 元素出堆 */
|
||||
public int poll()
|
||||
public int pop()
|
||||
{
|
||||
// 判空处理
|
||||
if (isEmpty())
|
||||
@ -168,7 +168,7 @@ public class my_heap
|
||||
maxHeap.print();
|
||||
|
||||
/* 堆顶元素出堆 */
|
||||
peek = maxHeap.poll();
|
||||
peek = maxHeap.pop();
|
||||
Console.WriteLine($"堆顶元素 {peek} 出堆后");
|
||||
maxHeap.print();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user