public static void mergesort(Comparable[] theArray, 
                             int first, int last) {
// ---------------------------------------------------------
// Sorts the items in an array into ascending order. 
// Precondition: theArray[first..last] is an array.
// Postcondition: theArray[first..last] is sorted in 
// ascending order.
// Calls: merge.
// ---------------------------------------------------------
  if (first < last) {
    // sort each half
    int mid = (first + last)/2;   // index of midpoint
    // sort left half theArray[first..mid]
    mergesort(theArray, first, mid);
    // sort right half theArray[mid+1..last]   
    mergesort(theArray, mid+1, last);  
 
    // merge the two halves
    merge(theArray, first, mid, last);
  }  // end if
}  // end mergesort