// assume array index at 0 For position = 1 to position size-1 HeapifyUp(ary, position) EndFor
While heap.size() > 0 swap(heap[0], heap[size]) size-- HeapifyDown(heap, 0, size) EndWhile