next up previous
Next: About this document Up: Assignment 1: The Deck Previous: The Deck class

Merge

  1. Using the pseudocode in Section 5.5, write the method called merge. Be sure to test it before trying to use it as part of a mergeSort.
  2. Write the simple version of mergeSort, the one that divides the deck in half and then uses sortDeck to sort the two halves. Then it uses merge to create a new, fully-sorted deck.

    Remember that sortDeck is a modifier and mergeSort is a function, which means that they get invoked differently:

      sortDeck (deck);              // modifies existing deck
      deck = mergeSort (deck);      // replaces old deck with new
  3. Write the fully recursive version of mergeSort.



Allen Downey
Wed Sep 13 16:43:50 EDT 2000