Bubble Sort Visualizer

Can someone help me to make a bubble sort visualizer using MIT?

The video below is an example of a bubble sort visualizer.
Bubble Sort - YouTube

Welcome Light.

What have you tried?

This look lke a fun project.

To visualize well, you need to use a Clock Timer instead of a loop, to give a chance for the user to see what's happening.

For a sort, one comparison per Clock Timer cycle should be okay.

If you want to add sounds, the Player component has an Event block that can fire at end of sound. You can use that instead of the Clock Timer to advance the show, assuming you have short audio clips.

Expect to need a few global variables:

  • The list being sorted
  • The index into that list marking the boundary between unsorted and sorted portions
  • the current sweep location across the lower part of the list.

There is an upcoming graph component you can try if you are lazy like me.
It is at the bottom of the FAQ

1 Like

Final_Exam_IT223 (1).aia (7.9 KB)

Above is the one I made but still, it is not okay. I wonder how can i fix it or what should i do to perfect it.

  • You loop too much. A visualizer should have no loops.
  • Your clock is too fast. 300 ms = 1/3 second.
  • Your text input blocks view of the bars with the keyboard. Just use a button to generate 10 random numbers, not to torture the user.
  • You are not showing the current bubble location in the bars
  • You are not refreshing ALL the bars after each step of the bubble
  • Make sure not to call the non-Clock sort procedure otherwise you spoil the show.