Initial situation is a heap that has been built before by function buildheap. Algorithm Heapsort rearranges the values of the nodes in such a way that in the end the tree contains the sorted sequence.
exchange the values of the last leaf and the root
downheap