Score: 100/100
Finished: 06.02.2025
push_swap is a sorting algorithm project that sorts a stack of integers with a limited set of operations. The objective is to sort the numbers using the fewest possible moves. This project is part of the 42 School curriculum.
To use push_swap, clone the repository in the root of your project using one of the following commands:
git clone [email protected]:blueyaGIT/push_swap.gitgit clone https://github.com/blueyaGIT/push_swap.gitgh repo clone blueyaGIT/push_swapThis will create a directory called push_swap/. Enter it with the command:
cd push_swapTo compile the program, run:
makeThis will generate the push_swap executable.
Execute the program with a list of integers:
./push_swap 4 67 3 87 23The program will output a sequence of operations to sort the numbers.
The following operations are used to manipulate the stacks:
sa- Swap the first two elements of stackA.sb- Swap the first two elements of stackB.ss- Swap the first two elements of both stacks.pa- Push the top element from stackBto stackA.pb- Push the top element from stackAto stackB.ra- Rotate stackAupwards.rb- Rotate stackBupwards.rr- Rotate both stacks upwards.rra- Reverse rotate stackA.rrb- Reverse rotate stackB.rrr- Reverse rotate both stacks.
- The program only accepts integer values.
- Duplicate numbers are not allowed.
- The stack is sorted using an efficient combination of operations.
For more details, refer to the project documentation or the 42 subject PDF.
