We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a782cf4 commit eb24272Copy full SHA for eb24272
Algorithms/countSort.js
@@ -0,0 +1,25 @@
1
+let countingSort = (arr) => {
2
+ let i = 0,
3
+ j = 0,
4
+ len = arr.length,
5
+ count = [];
6
+ let max = Math.min;
7
+ for(let i = 0; i<arr.length; i++){
8
+ if(arr[i] > max) max = arr[i];
9
+ }
10
+ for (i; i <= max; i++) {
11
+ count[i] = 0;
12
13
+ for (i = 0; i < len; i++) {
14
+ count[arr[i]] += 1;
15
16
+ for (i = 0; i <= max; i++) {
17
+ while (count[i] > 0) {
18
+ arr[j] = i;
19
+ j++;
20
+ count[i]--;
21
22
23
+ return arr;
24
+};
25
+
0 commit comments