This commit is contained in:
Emmanuelveslin 2024-04-25 08:17:40 +08:00 committed by GitHub
commit cb00cc1bed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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;
};