Mergesort method which is recursively called for sorting the input array.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
array |
Array
|
The array which should be sorted. |
cmp |
function
|
Compares two items in an array. |
start |
Number
|
Left side of the subarray. |
end |
Number
|
Right side of the subarray. |
Returns:
- Type:
-
Array
Array with sorted subarray.
Example
var array = [2, 4, 1, 5, 6, 7];
var mergeSort =
require('path-to-algorithms/src/sorting/mergesort').mergeSort;
mergeSort(array); // [1, 2, 4, 5, 6, 7]