refactor: Replace 'poll' with 'pop' in Heap (#416)

This commit is contained in:
Yudong Jin
2023-03-13 22:31:05 +08:00
committed by GitHub
parent 8aebbaad21
commit 28aacccf44
27 changed files with 91 additions and 152 deletions

View File

@ -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;

View File

@ -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();