Skip to content

Commit b9e519c

Browse files
author
Oskar Widmark
committed
fix: msd radix sort unnecessary swaps
1 parent 8fe8822 commit b9e519c

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/sorting-algorithms.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ export class SortingAlgorithms {
259259
const bucketStart = currentIndex;
260260
for (const a of bucket) {
261261
const swapIndex = indexMap[a.id];
262+
if (swapIndex === currentIndex) {
263+
currentIndex++;
264+
continue;
265+
}
262266
await this.drawAndSwap(arr, currentIndex, swapIndex);
263267

264268
indexMap[arr[swapIndex].id] = indexMap[arr[currentIndex].id];

0 commit comments

Comments
 (0)