Skip to content

Commit 12181be

Browse files
authored
Fix counts array visualization in Counting Sort
Final step did not correctly visualize decrementing the value in the counts array. It was decrementing the value but not updating the visualization.
1 parent 7138698 commit 12181be

File tree

1 file changed

+2
-1
lines changed
  • Divide and Conquer/Counting Sort

1 file changed

+2
-1
lines changed

Divide and Conquer/Counting Sort/code.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,16 @@ const array = Randomize.Array1D({ N, value: () => Randomize.Integer({ min: 0, ma
5858
const number = array[i];
5959
const count = counts[number];
6060
sortedArray[count - 1] = number;
61+
counts[number]--;
6162
// visualize {
6263
arrayTracer.select(i);
6364
countsTracer.select(number);
6465
sortedArrayTracer.patch(count - 1, sortedArray[count - 1]);
66+
countsTracer.patch(number, counts[number]);
6567
Tracer.delay();
6668
sortedArrayTracer.depatch(count - 1);
6769
countsTracer.deselect(number);
6870
arrayTracer.deselect(i);
6971
// }
70-
counts[number]--;
7172
}
7273
})();

0 commit comments

Comments
 (0)