consequentlythe process of generating heap of elements hn- in situ is described as followsl : div while do dec( )sift(ln- end in order to obtain not only partialbut full ordering among the elementsn sift steps have to followwhereby after each step the next (leastitem may be picked off the top of the heap once morethe question arises about where to store the emerging top elements and whether or not an in situ sort would be possible of course there is such solutionin each step take the last component (say xoff the heapstore the top element of the heap in the now free location of xand let sift down into its proper position the necessary - steps are illustrated on the heap of table the process is described with the aid of the procedure sift as followsr : - while do : [ ] [ : [ ] [ :xdec( )sift( rend table example of heapsort process the example of table shows that the resulting order is actually inverted thishowevercan easily be remedied by changing the direction of the ordering relations in the sift procedure this results in the following procedure heapsort (note that sift should actually be declared local to heapsort procedure sift (lrinteger)var ijintegerxitembegin :lj : * + : [ ]if ( ( [ja[ + ]then : + endwhile ( < ( [ ]do [ : [ ] :jj : * + if ( ( [ja[ + ]then : + end enda[ : end siftprocedure heapsortvar lrintegerxitembegin : div : - while do dec( )sift(lrend(adens _sorts *