Less than 1 minute
Home > @hz-9/algorithm > mergeSort
mergeSort() function
Merge sort algorithm.
归并排序。
Time complexity: O(n logn)
Time complexity badest case: O(n logn)
Time complexity goodest case: O(n logn)
Space complexity: O(n)
Signature:
mergeSort: <T>(list: T[], compareFu?: CompareFn<T>) => T[]Parameters
Parameter | Type | Description |
|---|---|---|
list | T[] | The array to be sorted. |
compareFu | CompareFn<T> | (Optional) The comparison function used to determine the order of the elements. |
Returns:
T[]
- The sorted array. (Is not original array)