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:
@ -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()
|
||||
|
||||
|
||||
@ -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")
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user