This project aims to increase one's knowledge of complexity in programming. Push_swap figures out what are the optimal moves to get any number of digits sorted. This is done through an implementation of the radix sort algorithm and pre-sorting.
Radix sort sorts the numbers based on their binary representation from right to left. The algorithm repeatedly performs operations on the stack until the numbers are sorted. The code includes functions for stack manipulation. Keep in mind this is but one of many algorithms, and might not be the optimal solution for getting the right set of instructions.
push_swap explanation in detail (Props to Leo Fu)
Clone the project
git clone https://github.com/RushMaverick/push_swap.git
Go to the project directory
cd push_swap
Make the program
make
Run the program
./push_swap 23 42 12 4 -2
You can input any numbers you want. If there are duplicates (two 2's for example.) it will say error.
The output will be what moves are required to sort the given numbers.
The following are the moves that were allowed for moving things within the stack.
Move | Functionality |
---|---|
Swap |
Swaps the two first elements of the given stack. |
Move | Functionality |
---|---|
Push |
Pushes the first element of the given stack to the top of the other given stack. |
Move | Functionality |
---|---|
Rotate |
Rotates the top of the given stack to the stack's bottom. |
Move | Functionality |
---|---|
Reverse Rotate |
Rotates the bottom of the given stack to the stack's top. |
Move | Functionality |
---|---|
Rotate Both |
Performs rotate on both stacks. |
Move | Functionality |
---|---|
Swap Both |
Performs swap on both stacks. |