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...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

248 Chap. 7 Internal Sortingsubarrays of size 2, which are in turn merged in<strong>to</strong> subarrays of size 4, <strong>and</strong> so on.We need <strong>to</strong> avoid having each merge operation require a new array. With somedifficulty, an algorithm can be devised that alternates between two arrays. A muchsimpler approach is <strong>to</strong> copy the sorted sublists <strong>to</strong> the auxiliary array first, <strong>and</strong> thenmerge them back <strong>to</strong> the original array. Here is a complete implementation formergesort following this approach:static

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

Saved successfully!

Ooh no, something went wrong!