Java Reference
In-Depth Information
Here is the output from running mergeSort on the example array:
sorting [14, 32, 67, 76, 23, 41, 58, 85]
sorting [14, 32, 67, 76]
sorting [14, 32]
sorting [14]
sorting [32]
merging [14] and [32]
sorting [67, 76]
sorting [67]
sorting [76]
merging [67] and [76]
merging [14, 32] and [67, 76]
sorting [23, 41, 58, 85]
sorting [23, 41]
sorting [23]
sorting [41]
merging [23] and [41]
sorting [58, 85]
sorting [58]
sorting [85]
merging [58] and [85]
merging [23, 41] and [58, 85]
merging [14, 32, 67, 76] and [23, 41, 58, 85]
It's also important to test the code on an array that doesn't divide into subarrays of
exactly equal size (i.e., one whose overall length is not a power of 2). Because it
employs integer division, our code makes the left subarray one element smaller than
the right subarray when the size is odd. Given an initial five-element list of ( 14, 32,
67, 76, 23 ) the algorithm prints the following output:
sorting [14, 32, 67, 76, 23]
sorting [14, 32]
sorting [14]
sorting [32]
merging [14] and [32]
sorting [67, 76, 23]
sorting [67]
sorting [76, 23]
sorting [76]
sorting [23]
merging [76] and [23]
merging [67] and [23, 76]
merging [14, 32] and [23, 67, 76]
Search WWH ::




Custom Search