A sorting algorithm visualizer built in Cuis Smalltalk using Morphic.
Shows a real-time animation of several sorting algorithms working on a collection of numbers, drawn as vertical bars. Bars currently being compared or swapped are highlighted in red; the rest stay blue.
SortingVisualizerWindow: the main window that holds the visualizer. Subclass ofSystemWindow.SortingVisualizerMorph: handles drawing and animation logic. Subclass ofBoxMorph.
Open a Workspace in Cuis and run:
SortingVisualizerWindow withBubbleSort: (1 to: 50) asOrderedCollection shuffled.
SortingVisualizerWindow withSelectionSort: (1 to: 50) asOrderedCollection shuffled.
SortingVisualizerWindow withInsertionSort: (1 to: 50) asOrderedCollection shuffled.
SortingVisualizerWindow withQuickSort: (1 to: 50) asOrderedCollection shuffled.
SortingVisualizerWindow withMergeSort: (1 to: 50) asOrderedCollection shuffled.
SortingVisualizerWindow withBogoSort: (1 to: 8) asOrderedCollection shuffled.You can change the collection size or use any collection of numbers. Keep the collection small for Bogo Sort, it can take a very long time to finish on anything bigger than a handful of elements.
- Bubble Sort
- Selection Sort
- Insertion Sort
- Quick Sort
- Merge Sort
- Bogo Sort
- Sorting runs on a separate process (
fork) so it doesn't block the UI. step/stepTimekeep the redraw loop running without needing user input.redrawNeededtells Morphic to calldrawOn:on the next cycle.Processor yieldhands off control between swaps so the UI can redraw.
- Cuis Smalltalk 6.x or later