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

@ -76,7 +76,7 @@ func TestMyHeap(t *testing.T) {
maxHeap.print()
/* 堆顶元素出堆 */
peek = maxHeap.poll()
peek = maxHeap.pop()
fmt.Printf("\n堆顶元素 %d 出堆后\n", peek)
maxHeap.print()

View File

@ -94,7 +94,7 @@ func (h *maxHeap) siftUp(i int) {
}
/* 元素出堆 */
func (h *maxHeap) poll() any {
func (h *maxHeap) pop() any {
// 判空处理
if h.isEmpty() {
fmt.Println("error")

View File

@ -18,7 +18,7 @@ func levelOrder(root *TreeNode) []int {
// 初始化一个切片,用于保存遍历序列
nums := make([]int, 0)
for queue.Len() > 0 {
// poll
// 队首元素出队
node := queue.Remove(queue.Front()).(*TreeNode)
// 保存结点值
nums = append(nums, node.Val)

View File

@ -36,7 +36,7 @@ func ArrToTree(arr []any) *TreeNode {
queue.PushBack(root)
i := 0
for queue.Len() > 0 {
// poll
// 队首元素出队
node := queue.Remove(queue.Front()).(*TreeNode)
i++
if i < len(arr) {