Commit 0ee18ca8 authored by Russ Cox's avatar Russ Cox

add heap.Remove

R=gri
DELTA=14  (14 added, 0 deleted, 0 changed)
OCL=34636
CL=34687
parent 1bbc044d
......@@ -52,6 +52,20 @@ func Pop(h HeapInterface) interface{} {
}
// Remove removes the element at index i from the heap.
// The complexity is O(log(n)) where n = h.Len().
//
func Remove(h HeapInterface, i int) interface{} {
n := h.Len()-1;
if n != i {
h.Swap(n, i);
down(h, i, n);
up(h, i);
}
return h.Pop();
}
func up(h HeapInterface, j int) {
for {
i := (j-1)/2;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment