Heap sort implementation.