Recursive version of insertion sort.
Time complexity: O(N^2).
Time complexity: O(N^2).
Parameters:
| Name | Type | Description |
|---|---|---|
array |
Array | Input array. |
cmp |
function | Optional. A function that defines an alternative sort order. The function should return a negative, zero, or positive value, depending on the arguments. |
max |
Number | Optional. Index of the element which place we should find in the current function call. |
- Source:
Returns:
Sorted array.
- Type
- Array
Example
var sort = require('path-to-algorithms/src/sorting/'+
'recursive-insertionsort').recursiveInsertionSort;
console.log(sort([2, 5, 1, 0, 4])); // [ 0, 1, 2, 4, 5 ]