minHeap added
Go / build (push) Successful in 29s

This commit is contained in:
Acid
2026-07-13 22:40:32 -04:00
parent ee7490988b
commit 65a9ba8fdb
3 changed files with 176 additions and 8 deletions
+6 -6
View File
@@ -85,16 +85,16 @@ func (h *MinHeap[T]) PopMin() (T, bool) {
last := len(h.Array) - 1
root := h.Array[0]
// swap places with last index
h.Array[0], h.Array[last] = h.Array[last], h.Array[0]
h.Array = h.Array[0:last]
h.siftDown(0)
// move last value to the root
h.Array[0] = h.Array[last]
// GC cleanup
h.Array[last] = zero
h.Array = h.Array[:last]
h.siftDown(0)
return root, true
}