Heap Sorting I
There are three repetitive steps involved in sorting the keys:
- Determine the value of the key in the first position of the heap (i.e., the smallest value).
- Move the largest value in the heap (last heap element) into the first position, and decrease the number of elements by one. At this point, the heap is out of order.
- Reorder the heap by exchanging the largest element with the smaller of its children and moving down the tree to the new position of the largest element until the heap is back in order.