Visualization of different sorting algorithms in C++ with SDL2 library.
A sorting Algorithm is an algorithm which puts the elements of a list in a certain order. There are a large no of sorting algorithms today, but a few dominate as they are optimal then others and faster in implementation. In this implementation of sorting visualizer we will be looking at some of these popularly used sorting algorithms and see visually their working. So the sorting algorithms picked by me are Selection sort , Insertion sort , Bubble sort , Heap sort , Merge sort and Quick sort. We have fixed the size of list as 130 but alloted the elements randomly to array. The sorting algorithms will sort in Ascending order of array. I have delayed faster algoriths like Merge sort , Heap sort to get proper visuals. Also as swapping occurs in sorting process , we get to hear some music sounds for the same as added features for the same.
You can run the cpp file available here in a code editor like Microsoft Visual studio once you download the project. Though you need special library called SDL for the code to function properly. I recommend you follow Lazy Foo' Productions' tutorial to setup SDL2 Library. PLEASE NOTE THAT the tutorial follows to setup SDL2 32-bit library but to run Sorting Visualizer, you have to use the 64-bit library. Just use x86_64-w64-mingw32 folder instead of i686-w64-mingw32 to setup the SDL2 files. After setting up the SDL2 library, just include the Sorting Visualizer.cpp file from the repository in your project with the build options as mentioned in the tutorial and build and run the project.
Available keys to control the input are :
- Press "0" for generating different random list of elements than the one mentioned.
- Press "1" to start Selection Sort Algorithm.
- Press "2" to start Insertion Sort Algorithm.
- Press "3" to start Bubble Sort Algorithm.
- Press "4" to start Merge Sort Algorithm.
- Press "5" to start Quick Sort Algorithm.
- Press "6" to start Heap Sort Algorithm.
- Press "q" to exit out of Visualizer.