Skip to content

Commit 82d67db

Browse files
committed
Radix sort animation bugs fixed
1 parent 498e01c commit 82d67db

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

‎src/components/Strategy/Algorithms/RadixSortLSD.js‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ class RadixSortLSD {
2727
let k = array.length;
2828
let sortedArray = new Array(k);
2929
let i = 0;
30-
let bucket = new Array(100);
30+
let counts = new Array(100);
3131

3232

3333
for(let i = 0; i < 100; i++) {
34-
bucket[i] = 0;
34+
counts[i] = 0;
3535
}
3636

3737
for(let i = 0; i < k; i++) {
38-
bucket[Math.floor(array[i] / exp) % 100]++;
38+
counts[Math.floor(array[i] / exp) % 100]++;
3939
}
4040

4141
for (i = 1; i < 100; i++) {
42-
bucket[i] += bucket[i - 1];
42+
counts[i] += counts[i - 1];
4343
}
4444

4545

@@ -48,7 +48,7 @@ class RadixSortLSD {
4848
await Animation.getAnimation(DELAY);
4949
const oldValue = array[i]; // value being sorted to a new index
5050
const oldIndex = this.getIndexDOM(oldValue, DOM); // index of old value
51-
const sortedIndex = bucket[Math.floor(array[i] / exp) % 100] - 1;
51+
const sortedIndex = counts[Math.floor(array[i] / exp) % 100] - 1;
5252
const valueInOldArray = array[sortedIndex];
5353

5454
Animation.swap(oldIndex, sortedIndex); // SG 07/10/2022 22:35 swap animation
@@ -57,7 +57,7 @@ class RadixSortLSD {
5757
DOM[sortedIndex].style.backgroundColor = SORTED_COLOR;
5858
}
5959
sortedArray[sortedIndex] = oldValue;
60-
bucket[Math.floor(array[i] / exp) % 100]--;
60+
counts[Math.floor(array[i] / exp) % 100]--;
6161
}
6262

6363

0 commit comments

Comments
 (0)