Page 246 - DCAP201_FUNDAMENTALS_OF_DATA_STRUCTURES
P. 246

Unit 13: Sorting




          Swap 19 with the last element of the heap (As 10 will be adjusted in the heap, its cell will no  Notes
          longer be a part of the heap. Instead it becomes a cell from the sorted array):











          The element 10 will have to go down in the tree:













          And again down one more level, 10 is less that 15, so it cannot be inserted in the previous hole:













          Now 10 has found the right spot:













          The next greatest element is 17, which has to be removed:














          Also, swap 17 with the last element of the heap. As 10 will be adjusted in the heap, its cell will no
          longer be a part of the heap, instead it becomes a cell from the sorted array:




                                           LOVELY PROFESSIONAL UNIVERSITY                                   239
   241   242   243   244   245   246   247   248   249   250   251