Sorting

Following are various sorts I have coded with animations in Javascript. In some of them, the sort function recursively calls itself with a delay so that one can see the changes (vs. all finishing in the blink of an eye.)


In sorts with nested loops this will not work, so the moves/swaps are queued up in an array using the push() method.

Once the sort is done, the array is reversed using the reverse() method to allow popping them off in FIFO order.

Then the playback function uses the pop() method to remove the entries from the array, and recursively calls itself.

Thus it sorts the bar chart during playback (only the array containing the numbers was sorted in the sort function).

I got the idea to queue the moves after reading a post by Joshua Kehn on stackoverlow.com.


The animation which changes the bar heights on Reset is done with CSS-3.