// CODE
// Recursive merge sort algorithm
template
void MergeSort ( ItemType values[ ] , int first , int last )
// Pre: first <= last
// Post: Array values[first..last] sorted into
// ascending order.
{
if ( first < last ) // general case
{
int middle = ( first + last ) / 2 ;
MergeSort ( values, first, middle ) ;
MergeSort( values, middle + 1, last ) ;
// now merge two subarrays
// values [ first . . . middle ] with
// values [ middle + 1, . . . last ].
Merge(values, first, middle, middle + 1, last);
}
}
|