diff --git a/codes/go/chapter_heap/my_heap.go b/codes/go/chapter_heap/my_heap.go index 0b3d0a3b..cd3015f6 100644 --- a/codes/go/chapter_heap/my_heap.go +++ b/codes/go/chapter_heap/my_heap.go @@ -98,6 +98,7 @@ func (h *maxHeap) poll() any { // 判空处理 if h.isEmpty() { fmt.Println("error") + return nil } // 交换根结点与最右叶结点(即交换首元素与尾元素) h.swap(0, h.size()-1) diff --git a/docs/chapter_heap/heap.md b/docs/chapter_heap/heap.md index 15d22e78..e1d29fe3 100644 --- a/docs/chapter_heap/heap.md +++ b/docs/chapter_heap/heap.md @@ -606,6 +606,7 @@ comments: true // 判空处理 if h.isEmpty() { fmt.Println("error") + return nil } // 交换根结点与最右叶结点(即交换首元素与尾元素) h.swap(0, h.size()-1)