在学习golang container/heap的时候比较疑惑?
参考文档:https://docs.studygolang.com/pkg/container/heap/#Pop
文档中对于heap的pop的解释是弹出下标为0的元素,下面是文档中的解释
Pop removes and returns the minimum element (according to Less) from the heap. The complexity is O(log n) where n = h.Len(). Pop is equivalent to Remove(h, 0).
但是这个文档给的例子却不是按照弹出index为0的元素来的。文档中的示例把n-1下标元素给弹出来了, 这不是跟方法定义不一样吗?有没有大佬解惑?
func (h *IntHeap) Pop() interface{} {
old := *h
n := len(old)
x := old[n-1]
*h = old[0 : n-1]
return x
}