This project is a visualization of the "shuffle sort" algorithm using Go and the tcell library. The program generates a random array of integers and then continuously shuffles it until it becomes sorted, displaying each shuffle attempt in real-time. Performance metrics such as elapsed time, iteration count, and operations per second are shown on the screen.
- Real-Time Visualization: Displays the array in a grid, with each element represented by a vertical bar.
- Performance Metrics: Shows the current iteration, total elapsed time, and operations per second.
- Shuffle Sort Algorithm: Demonstrates the inefficient, but visually interesting, shuffle sort algorithm.
- Clone this repository.
- Install the required
tcellpackage:go get github.com/gdamore/tcell/v2
- Run the program:
go run main.go
The program uses the shuffle sort algorithm:
- Randomly initializes an integer array.
- Checks if the array is sorted.
- If not, shuffles the array and counts the attempt.
- If sorted, displays the final sorted array along with metrics.
To quit the program, press any key.
sliceRandomInitialize: Initializes the array with random integers.shuffleSlice: Shuffles the array.isSorted: Checks if the array is sorted.visualizeArray: Updates the screen with the array and performance metrics.
The program will display an array visualization with the following information:
Iteration: [current iteration]
Speed: [operations per second] ops/sec
Time Elapsed: [elapsed time]
tcelllibrary for handling terminal graphics.
This project serves as an example of inefficient sorting algorithms and is best used for educational or entertainment purposes. Due to the nature of shuffle sort, the number of iterations may be very high.
This project is licensed under the MIT License.