added counting sort repo

This commit is contained in:
Emmanuelveslin 2019-10-05 23:48:03 +05:30 committed by GitHub
parent dc1047df72
commit 9dd7b3cd01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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