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:
Panzki
2017-10-10 12:30:58 +02:00
parent 8b8575d058
commit a7a192ad08

View File

@ -24,7 +24,7 @@ function radixSort(items, RADIX) {
for (var j = 0; j < items.length; j++) {
var tmp = items[j] / placement;
buckets[Math.round(tmp % RADIX)].push(j);
buckets[Math.floor(tmp % RADIX)].push(items[j]);
if (maxLength && tmp > 0) {
maxLength = false;
}
@ -34,7 +34,7 @@ function radixSort(items, RADIX) {
for (var b = 0; b < RADIX; b++) {
var buck = buckets[b];
for (var k = 0; k < buck.length; k++) {
items[a] = k;
items[a] = buck[k];
a++;
}
}