小于 1 分钟
Home > @hz-9/algorithm > countingSort
countingSort() function
Counting sort algorithm.
计数排序。
Time complexity: O(n+k)
Time complexity badest case: O(n+k)
Time complexity goodest case: O(n+k)
Space complexity: O(n+k)
Signature:
countingSort: <T>(list: T[], toNumber?: ToNumberFn<T>) => T[]Parameters
Parameter | Type | Description |
|---|---|---|
list | T[] | The array to be sorted. |
toNumber | ToNumberFn<T> | (Optional) The function used to convert elements to numbers. |
Returns:
T[]
- The sorted array. (Is original array)