Sorting
Sorting Visualizer (C++)
This is an educational software that graphically shows how several sorting algorithms work.
You can add your own sorting algorithms following the instructions Adding custom sorting algorithm section.
Dependencies
-SDL2.0
-SDL_ttf
Adding custom sorting algorithm:
Write the sorting function in Program.cpp The function data type MUST be void, and MUST take one and ONLY ONE parameter of type std::vector<int>*.
Your sorting function MUST set the flag Visualizer::getSorted() = true; before exiting. This flag tells the Visualizer the sorting is finished, so that it can go to the next sorting function.
In the function body, use the following flags to interact with the visualizer:
Visualizer::getGreen() = [some integer]; //[some integer] index in the array will be rendered green
Visualizer::getRed() = [some integer]; //[some integer] index in the array will be rendered red
Visualizer::getItr()++; //this increases the comparisson count in the visualizer
Visualizer::sleep(); //sleep used every time the function does a comparisson
Visualizer::sleep_final(); //sleep used at the end of the function, to allow the user to visualize the sorted data
To add your sorting algorithm to the visualizer:
Use: Visualizer::AddAlgorithm(functionName, “Algorithm Name”, parameters);
This is an example:
Visualizer::AddAlgorithm(quickSort, "Quick Sort", PARAMETERS( 5, //bar width 10, //bar height scale 160, //number of elements in array 50, //max number generated for the array 3, //delay 2000 //final delay ));
Or use Visualizer::GetParameters(); to get the default parameters.
Finally, call Visualizer::Init(); to start the visualization.
Go to Sorting/src/Program.cpp to see a functional example.