mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-26 01:06:28 +08:00
Merge pull request #258 from ShiMaRing/master
fix: polling from an empty heap will cause panic
This commit is contained in:
commit
736e368d8b
2 changed files with 2 additions and 0 deletions
|
@ -98,6 +98,7 @@ func (h *maxHeap) poll() any {
|
|||
// 判空处理
|
||||
if h.isEmpty() {
|
||||
fmt.Println("error")
|
||||
return nil
|
||||
}
|
||||
// 交换根结点与最右叶结点(即交换首元素与尾元素)
|
||||
h.swap(0, h.size()-1)
|
||||
|
|
|
@ -606,6 +606,7 @@ comments: true
|
|||
// 判空处理
|
||||
if h.isEmpty() {
|
||||
fmt.Println("error")
|
||||
return nil
|
||||
}
|
||||
// 交换根结点与最右叶结点(即交换首元素与尾元素)
|
||||
h.swap(0, h.size()-1)
|
||||
|
|
Loading…
Reference in a new issue