Counting sort algorithm. It's correct only
for array of integers.
Time complexity: O(N).
Time complexity: O(N).
- Source:
Parameters:
Name | Type | Description |
---|---|---|
array |
Array
|
Array which should be sorted. |
Returns:
- Type:
-
Array
Sorted array.
Example
var sort = require('path-to-algorithms/src/' +
'sorting/countingsort').countingSort;
console.log(sort([2, 5, 1, 3, 4])); // [ 1, 2, 3, 4, 5 ]