This commit is contained in:
Emmanuelveslin 2024-07-17 10:38:25 +09:00 committed by GitHub
commit 1c8488562a
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;
};