Esempio n. 1
0
// Removes and returns the minimum element of h.
func PopMin(h heap.Interface) interface{} {
	n := h.Len() - 1
	h.Swap(0, n)
	x := h.Pop()
	siftDownMin(h, 0, n)
	return x
}
Esempio n. 2
0
// Removes and returns the maximum element of h.
func PopMax(h heap.Interface) interface{} {
	n := h.Len()
	if n <= 2 {
		return h.Pop()
	}

	i := 1
	if h.Less(1, 2) {
		i = 2
	}
	h.Swap(i, n-1)
	x := h.Pop()
	siftDownMax(h, i, n-1)
	return x
}