Lo-res sort display. David G. Schwaegler.
The program presented here is a visual aid to understanding various algorithms for sorting lists into rank order. The user may see the operation of the infamous Bubble Sort and the much more efficient Shell Sort in action. A place was left open in the menu to encourage the inclusion of other sorting routines. The low-resolution graphics capabilities of Applesoft are used, but the program could be adapted to machines without graphics by using PRINT, VTAB and TAB statements in place of the PLOT statements. Program Operation
The program is generously REMarked to explain the specific line functions. Line 100 begins the routine which chooses data points. Each of the 40 points of the Apple screen horizontal (X) axis is assigned a vertical axis (Y) value. Line 130 checks to make certain that no two of these values are alike.
The job of the sorting algorithm is to rearrange those Y values so that they increase in value as the X values increase. Each interchange is shown on the screen using the subroutine at 40 for the Bubble Sort and at 45 for the Shell Sort. The SRN (X,Y) statement in Applesoft returns the color of the square plotted by the coordinates in the argument. By using SCRN just before the plotting subroutines are called, the colors are preserved and assigned to the data points as they are placed in their new positions. This color coding of the points helps the viewer follow the action. The differences in speed and strategy of sorting routines are much clearer after viewing them while they work.