Skip to content

Commit 92f9b52

Browse files
authored
Merge pull request #7 from zanliang4tz/dw-branch-2
Highlights array green when all sorted
2 parents 8bdb10f + ae6dad9 commit 92f9b52

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/algorithms/controllers/msort_arr_bup.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -426,16 +426,23 @@ export function run_msort() {
426426
runlength = 2 * runlength;
427427
chunker.add('runlength2', (vis, c_rlength) => {
428428
assignVarToA(vis, 'left', undefined, size);
429-
if (c_rlength > size) {
430-
assignVarToA(vis, 'done', size, size);
431-
}
432-
else {
429+
set_simple_stack(vis.array, [c_rlength]);
430+
431+
if (c_rlength < size) {
433432
displayRunlength(vis, c_rlength, size);
434433
}
435-
set_simple_stack(vis.array, [c_rlength]);
434+
436435
}, [runlength]);
437436
}
438437

438+
chunker.add('Done', (vis) => {
439+
for (let i = 0; i < size; i++) {
440+
highlight(vis, i, colorC);
441+
}
442+
assignVarToA(vis, 'done', size, size);
443+
}, []);
444+
445+
439446
// We compute and fix the max value in each array so they don't get re-scaled as we
440447
// shuffle elements between arrays
441448
const maxValue = entire_num_array.reduce((acc, curr) => (acc < curr ? curr : acc), 0);

src/algorithms/pseudocode/msort_arr_bup.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Mergesort(A, size) \\B Main
2020
merge all consecutive pairs of runs of length runlength \\Ref MergeAll
2121
runlength <- runlength * 2 // merging runs doubles the run length \\B runlength2
2222
\\In}
23+
// Done \\B Done
2324
\\Code}
2425
2526
\\Code{

0 commit comments

Comments
 (0)