Skip to content

Commit 268fa1c

Browse files
committed
fix: set the maxValue so the array size doesn't change too much
1 parent aafd54d commit 268fa1c

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/algorithms/controllers/msort_arr_nat.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,15 @@ export function run_msort() {
178178

179179
//let setLargestValue = 0;
180180

181-
chunker.add('Main', (vis, a, b) => {
181+
chunker.add('Main', (vis, a, b, c_rcount) => {
182182
vis.array.set(a, 'msort_arr_nat');
183-
if (isMergeCopyExpanded()) vis.arrayB.set(b, 'msort_arr_nat');
184-
}, [A, B]);
183+
if (c_rcount === 0) {
184+
vis.array.setLargestValue(maxValue);
185+
} if (isMergeCopyExpanded()) {
186+
vis.arrayB.set(b, 'msort_arr_nat');
187+
vis.arrayB.setLargestValue(maxValue);
188+
}
189+
}, [A, B, runcount]);
185190

186191
do {
187192

@@ -457,6 +462,8 @@ export function run_msort() {
457462
assignVarToA(vis, 'done', size, size);
458463
}, []);
459464

465+
const maxValue = entire_num_array.reduce((acc, curr) => (acc < curr ? curr : acc), 0);
466+
460467
return A;
461468
}
462469

0 commit comments

Comments
 (0)