Skip to content

Commit 52d1b5e

Browse files
committed
Quicksort base case bugs etc fixed
1 parent ed0fee8 commit 52d1b5e

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/algorithms/controllers/quickSort_shared.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -569,29 +569,26 @@ cur_finished_stack_frames, cur_i, cur_j, cur_pivot_index, cur_depth) // refresh
569569
}
570570
// array of size 1, already sorted
571571
// has a conditional to specify which line it jumps to depending on the expanding and collapsing
572-
// XXX not sure this is a good idea - recursion clearer in
573-
// animation if final "// Done" is stopped at
574-
// for each recursive call - user can mentally prepare for what we
575-
// jump back to?
572+
// BUGS plus not a great idea
573+
// Modified so we stop at "// Done" for all base cases (could add
574+
// other cases also XXX); code could be simplified.
576575
else if (left < a.length) {
577-
finished_stack_frames.push(real_stack.pop());
578-
let size_one_bookmark = isRecursionExpanded()
579-
? QS_BOOKMARKS.SHARED_quicksort_left_to_i_minus_1
580-
: QS_BOOKMARKS.SHARED_skip_step;
576+
// let size_one_bookmark = isRecursionExpanded()
577+
// ? QS_BOOKMARKS.SHARED_quicksort_left_to_i_minus_1
578+
// : QS_BOOKMARKS.SHARED_skip_step;
581579

582580
chunker.add(
583-
size_one_bookmark,
581+
// size_one_bookmark,
582+
QS_BOOKMARKS.SHARED_done_qs,
584583
(vis, l) => {
585584
vis.array.sorted(l);
586585
},
587586
[left],
588587
depth);
588+
finished_stack_frames.push(real_stack.pop());
589589
} else {
590+
chunker.add(QS_BOOKMARKS.SHARED_done_qs);
590591
finished_stack_frames.push(real_stack.pop());
591-
chunker.add(QS_BOOKMARKS.SHARED_done_qs, refresh_stack, [
592-
real_stack,
593-
finished_stack_frames,
594-
], depth);
595592
}
596593

597594
return a; // Facilitates testing

0 commit comments

Comments
 (0)