This project implements various sorting algorithms in C++. The user can choose between different sorting methods through a menu interface.
The following sorting algorithms are included:
-
Bubble Sort: A simple comparison-based sorting algorithm that repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order. The process is repeated until the list is sorted.
-
Quick Sort: An efficient sorting algorithm that uses a divide-and-conquer approach. It selects a 'pivot' element from the array and partitions the other elements into two sub-arrays according to whether they are less than or greater than the pivot. The sub-arrays are then sorted recursively.
-
Merge Sort: Another divide-and-conquer algorithm that divides the array into halves, sorts each half, and then merges the sorted halves back together. This algorithm is known for its efficiency and stability.
To build the project, you need to have CMake installed. Follow these steps:
- Clone the repository or download the project files.
- Open a terminal and navigate to the project directory.
- Create a build directory:
mkdir build cd build
- Run CMake to configure the project:
cmake ..
- Build the project:
cmake --build .
Run the application from the build directory using the following command in powershell:
.\Debug\SortingAlgorithms.exe
Upon running the application, a menu will be displayed allowing you to select one of the sorting algorithms. After making a selection, the program will generate a random array, sort it using the chosen algorithm, and visualize the sorting process with ASCII art.
main.cpp
: Contains the main function and menu logicuitls.h
andutils.cpp
: Utility functions for displaying the array.bubble_sort.h
andbubble_sort.cpp
: Implementation of the Bubble Sort algorithm.quick_sort.h
andquick_sort.cpp
: Implementation of the Quick Sort algorithm.merge_sort.h
andmerge_sort.cpp
: Implementation of the Merge Sort algorithm.
Feel free to contribute to this project by adding more sorting algorithms or improving the existing implementations. Please submit a pull request for any changes you wish to propose.
This project is licensed under the MIT License - see the LICENSE file for details.