12.07.2015 Views

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

258 Chap. 7 Internal SortingOriginal Numbers73 6 57 88 60 42 83 72 48 85736 5788 60 42 8372 48 85Build Heap88 85 83 72 73 42 57 6 48 6088858372 73 42 576 48 60Remove 8885 73 83 72 60 42 57 6 48 888573 8372 60 42 576 48Remove 8583 73 57 72 60 42 48 6 85 888373 5772 60 42 48673Remove 8372 57 6 60 42 48 83 85 887372 576 60 42 48Figure 7.10 An illustration of Heapsort. The <strong>to</strong>p row shows the values in theiroriginal order. The second row shows the values after building the heap. Thethird row shows the result of the first removefirst operation on key value 88.Note that 88 is now at the end of the array. The fourth row shows the result of thesecond removefirst operation on key value 85. The fifth row shows the resul<strong>to</strong>f the third removefirst operation on key value 83. At this point, the lastthree positions of the array hold the three greatest values in sorted order. Heapsortcontinues in this manner until the entire array is sorted.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!