Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a7a192a

Browse files
committed
Fixed a bug in the radix sort algorithm, that would sort the indexes of the passed array instead of the actual array items.
1 parent 8b8575d commit a7a192a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

‎Sorts/radixSort.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function radixSort(items, RADIX) {
2424

2525
for (var j = 0; j < items.length; j++) {
2626
var tmp = items[j] / placement;
27-
buckets[Math.round(tmp % RADIX)].push(j);
27+
buckets[Math.floor(tmp % RADIX)].push(items[j]);
2828
if (maxLength && tmp > 0) {
2929
maxLength = false;
3030
}
@@ -34,7 +34,7 @@ function radixSort(items, RADIX) {
3434
for (var b = 0; b < RADIX; b++) {
3535
var buck = buckets[b];
3636
for (var k = 0; k < buck.length; k++) {
37-
items[a] = k;
37+
items[a] = buck[k];
3838
a++;
3939
}
4040
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /