just swapped with the root is shown in gray background notice that value is the largest value in the original array of unsorted values and when sorted belongs in this exact position at the end of the array finallythe value copied from the leaf to the root has to be sifted downas illustrated in figure (dif we repeat this same processswapping the root value with the last item in the subarray that comprises the heapfor each item in the heap we end up with sorted array of values in ascending order figure illustrates the remaining steps in extracting each value from the heap and storing them in the same array the shaded part of the array shows the values that have been removed from the heap and placed in sorted order while the elements with white background show those that comprise the heap are currently part of the array the boldfaced values indicate those that were affected by the sift-down operation figure the steps in extracting the values from the heap into the same array that will store the resulting sequence the implementation for this improved version of the heapsort algorithm is provided in listing it does not use the maxheap class from earlierbut it does rely on siftup(and siftdown(functions like those used with the class