Implements Heap sort.