Skip to content

Commit fe3adcf

Browse files
authored
Fix counts array visualization in Counting Sort (#28)
* 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. * Add countsTracer.depatch My previously committed code left the boxes in the counts array colored red, so I realized I had forgotten to add a depatch after the patch that I added at line 66
1 parent 7138698 commit fe3adcf

File tree

1 file changed

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

1 file changed

+3
-1
lines changed

Divide and Conquer/Counting Sort/code.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,17 @@ 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);
69+
countsTracer.depatch(number);
6770
countsTracer.deselect(number);
6871
arrayTracer.deselect(i);
6972
// }
70-
counts[number]--;
7173
}
7274
})();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy