chickadee » heap » heap-extract-extremum!

heap-extract-extremum! heapprocedure

Return and delete the heap's extremum (min or max).

heap
The heap from which to extract
(define (heap-extract-extremum! heap)
  (let ((extremum (heap-extremum heap)))
    (heap-set! heap 0 (heap-ref heap (- (heap-size heap) 1)))
    (heap-size-set! heap (- (heap-size heap) 1))
    (heapify!/index heap 0)
    extremum))