Compare commits

...

2 Commits

Author SHA1 Message Date
Emmanuelveslin
cb00cc1bed
Merge 9dd7b3cd01 into 2c67b48c21 2024-04-25 08:17:40 +08:00
Emmanuelveslin
9dd7b3cd01
added counting sort repo 2019-10-05 23:48:03 +05:30

22
countingsort.js Normal file
View File

@ -0,0 +1,22 @@
let countingSort = (arr, min, max) => {
let i = min,
j = 0,
len = arr.length,
count = [];
for (i; i <= max; i++) {
count[i] = 0;
}
for (i = 0; i < len; i++) {
count[arr[i]] += 1;
}
for (i = min; i <= max; i++) {
while (count[i] > 0) {
arr[j] = i;
j++;
count[i]--;
}
}
return arr;
};