mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-06 17:50:39 +08:00
Fixed a bug in the radix sort algorithm, that would sort the indexes of the passed array instead of the actual array items.
This commit is contained in:
@ -24,7 +24,7 @@ function radixSort(items, RADIX) {
|
|||||||
|
|
||||||
for (var j = 0; j < items.length; j++) {
|
for (var j = 0; j < items.length; j++) {
|
||||||
var tmp = items[j] / placement;
|
var tmp = items[j] / placement;
|
||||||
buckets[Math.round(tmp % RADIX)].push(j);
|
buckets[Math.floor(tmp % RADIX)].push(items[j]);
|
||||||
if (maxLength && tmp > 0) {
|
if (maxLength && tmp > 0) {
|
||||||
maxLength = false;
|
maxLength = false;
|
||||||
}
|
}
|
||||||
@ -34,7 +34,7 @@ function radixSort(items, RADIX) {
|
|||||||
for (var b = 0; b < RADIX; b++) {
|
for (var b = 0; b < RADIX; b++) {
|
||||||
var buck = buckets[b];
|
var buck = buckets[b];
|
||||||
for (var k = 0; k < buck.length; k++) {
|
for (var k = 0; k < buck.length; k++) {
|
||||||
items[a] = k;
|
items[a] = buck[k];
|
||||||
a++;
|
a++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user