mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-06 09:28:26 +08:00
Updated the count sort algorithm with stable implementation. Added ES6 syntactic sugar to the syntax
This commit is contained in:
@ -12,12 +12,8 @@ const countingSort = (arr, min, max) => {
|
|||||||
// Create an auxiliary resultant array
|
// Create an auxiliary resultant array
|
||||||
const res = []
|
const res = []
|
||||||
// Create the freq array
|
// Create the freq array
|
||||||
const count = []
|
|
||||||
let len = max - min + 1
|
let len = max - min + 1
|
||||||
|
const count = new Array(len).fill(0)
|
||||||
for (let i = 0; i < len; i++) {
|
|
||||||
count[i] = 0
|
|
||||||
}
|
|
||||||
// Populate the freq array
|
// Populate the freq array
|
||||||
for (let i = 0; i < arr.length; i++) {
|
for (let i = 0; i < arr.length; i++) {
|
||||||
count[arr[i] - min] += 1
|
count[arr[i] - min] += 1
|
||||||
|
Reference in New Issue
Block a user