Pop() interface{}
}
-
-// A heaper must be initialized before any of the heap operations
+// A heap must be initialized before any of the heap operations
// can be used. Init is idempotent with respect to the heap invariants
// and may be called whenever the heap invariants may have been invalidated.
// Its complexity is O(n) where n = h.Len().
}
}
-
// Push pushes the element x onto the heap. The complexity is
// O(log(n)) where n = h.Len().
//
up(h, h.Len()-1)
}
-
// Pop removes the minimum element (according to Less) from the heap
// and returns it. The complexity is O(log(n)) where n = h.Len().
// Same as Remove(h, 0).
return h.Pop()
}
-
// Remove removes the element at index i from the heap.
// The complexity is O(log(n)) where n = h.Len().
//
return h.Pop()
}
-
func up(h Interface, j int) {
for {
i := (j - 1) / 2 // parent
}
}
-
func down(h Interface, i, n int) {
for {
j1 := 2*i + 1