mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-11-10 11:09:43 +08:00
Compare commits
2 Commits
1c8488562a
...
cb00cc1bed
Author | SHA1 | Date | |
---|---|---|---|
|
cb00cc1bed | ||
|
9dd7b3cd01 |
22
countingsort.js
Normal file
22
countingsort.js
Normal 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;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user