Skip to content

Commit 984d3a2

Browse files
committed
msort_arr_bup bug fix++
1 parent e187686 commit 984d3a2

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/algorithms/controllers/msort_arr_bup.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,15 @@ export function run_msort() {
144144
// highlight2Runlength(vis, left_2, mid_2, right_2, runAColor, runBColor);
145145
}, [A, left, runlength]);
146146

147-
while ((left + runlength) <= size) {
147+
// while ((left + runlength) < size) - want to show this chunk
148+
// before loop exit
149+
/* eslint-disable no-constant-condition */
150+
while (true) {
148151
chunker.add('MergeAllWhile', () => {
149152
//no animation
150153
}, []);
154+
if ((left + runlength) >= size)
155+
break;
151156

152157
let mid = left + runlength - 1;
153158
let right = Math.min(mid + runlength, (size - 1));

src/algorithms/controllers/msort_arr_td.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import { msort_arr_td } from '../explanations';
1111
import {colors} from '../../components/DataStructures/colors';
1212

13-
// Should be consistent with BUP/Nat merge sort
13+
// Animation should be consistent with BUP/Nat merge sort
1414
// XXX (could make code more similar and use shared code here)
1515
const apColor = colors.apple;
1616
const runAColor = colors.peach;
@@ -619,6 +619,12 @@ export function run_msort() {
619619
if (cur_ap2 < a.length)
620620
assignVarToA(vis, 'ap2', cur_ap2);
621621
assignVarToA(vis, 'max2', cur_max2);
622+
for (let i = cur_left; i <= cur_max1; i++) {
623+
highlight(vis, i, runAColor);
624+
}
625+
for (let i = cur_max1 + 1; i <= cur_max2; i++) {
626+
highlight(vis, i, runBColor);
627+
}
622628
vis.arrayB.set(b, 'msort_arr_td');
623629
for (let i = cur_left; i <= cur_bp - 1; i++) {
624630
highlightB(vis, i, sortColor);

src/algorithms/pseudocode/msort_arr_bup.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ MergeAll
3030
\\Expl{ Unless size is a power of two there can be times when the
3131
number of runs is odd and we have a "leftover" run at the end
3232
(with length <= runlength), that will be merged in a later iteration.
33+
If left is not displayed it is one past the right end of the
34+
array.
3335
\\Expl}
3436
\\In{
3537
mid <- left + runlength - 1 // first run is A[left..mid] \\B mid

0 commit comments

Comments
 (0)