While studying Computer Sciences some years ago I made the experience that some sort algorithms are quite hard to understand by examining their source (or pseudo) code. My fellow students and I spent quite some time simulating the steps of the algorithms on paper. At this time I had the idea to write a program, which would free me from this tedious work by visualizing the things that happen while sorting on the screen.
Well, this first attempt never worked the way I supposed it to work, because I mixed the aspects of sorting with the aspects of visualizing. Therefore it was nearly impossible to extend the program with new sort algorithms.
Now some years later (and sadly enough no student anymore) I decided to gave this little program a second try. This time I used some Design Patters (Observer and Strategy in the first place) to avoid the problems I had in the previous version. The main focus was to separate the algorithms as far as possible from the other responsibilities of the application like visualization, threading and user interaction. I use a number of bars with different height to visualize the sort array. Before starting to sort, a random distribution of the bars is produced. After a successful sort process the bars should be ordered ascending from left to right (screenshots). If the sort array is accessed, events are triggered to update the visualization. This way a viewer get quite a good impression of how a particular algorithm works.
VisualSort is a standalone Java application, which requires a Java Runtime Environment 5 or greater in order to run. You may download a JRE here. The platform independent Swing library is used for the Graphical User Interface.
The current state of the application is quite rudimentary, but should be OK as a basis for further work. Right now it's possible to visualize four different sort algorithms, namely TrippleSort (very slow), QuickSort, SelectionSort and the famous BubbleSort.
The current version can be downloaded here: http://sourceforge.net/project/showfiles.php?group_id=186004
You can start the application from the command line like this:
java -jar VisualSort.jar
Windows-Users should achieve the same effect by doubleclicking on the Jar-Archive. If a java.exe is not already associated with the .jar extension you have to do that yourself.
Feel free to experiment with the source code of the application. A explanation of how to get anonymous (read only) access to the cvs repository can be found at:
http://sourceforge.net/cvs/?group_id=186004
I will provide a README file in the root directory which explains how to get this stuff running. I use the eclipse IDE to develop this application. Therefore it is probably the easiest solution to check out the project with this IDE.
I hope I find some time to improve the application.
Some topics I would like to adress in the future are:
richer user settings, e.g. different screen sizes, configurable timings and colors
finer control of the sort process, like pausing or single step mode
gathering of statistics
refactoring of the threading stuff (wait/notify doesn't currently work)
... and of cause many additional sort algorithms
I would be pleased if some other developers would join me in this project. You can reach me at thofis@users.sourceforge.net