This repository aims to combine all (eventually) sorting algorithms into one piece of code as a quick refresher for beginners and experts. It also measures the time taken by each sorting algorithm function.
Time Complexity:
- Average: O(n²)
- Worst: O(n²)
Description:
Loops through the list while constantly moving the smallest value in the unsorted part to the end of the sorted part.
Time Complexity:
- Average: O(n²)
- Worst: O(n²)
Description:
Loops through the list and moves each element value down into the correct location of the currently sorted part.
Time Complexity:
- Average: O(n²)
- Worst: O(n²)
Description:
Loops through the list and repeatedly compares adjacent elements and swaps them if needed.
Time Complexity:
- Average: O(n log n)
- Worst: O(n²)
Description:
Paritions array into two based off of a pivot index. One holds values less than pivot, the other holds values higher than pivot. Then recursively sorts the two arrays.
Use the following command in your terminal:
g++ sortOfAllSort.cpp -o sortOfAllSort && ./sortOfAllSort-
On Ubuntu/Debian:
bash sudo apt install g++ -
On macOS (with Homebrew):
bash brew install gcc
-
Open
sortOfAllSort.cppin Visual Studio. -
Use the build and run buttons to compile and execute.
- If you have
g++installed (e.g., via MinGW or Windows Subsystem for Linux), run the following in Command Prompt, PowerShell, or WSL:
g++ sortOfAllSort.cpp -o sortOfAllSort && sortOfAllSort💡 Tip: Ensure g++ is in your system's PATH.
You can check with bash g++ --version in your terminal.