Heapsort
Given BuildHeap(), an in-place sorting algorithm is easily constructed:
- Maximum element is at A[1]
- Discard by swapping with element at A[n]
- Decrement heap_size[A]
- A[n] now contains correct value
- Restore heap property at A[1] by calling Heapify()
- Repeat, always swapping A[1] for A[heap_size(A)]