Push_swap is a 42 project that aims to implement two programs: push_swap
and checker
. The push_swap
program takes a list of integers as input and sorts them using a limited set of operations on two stacks. The checker
program verifies if the list of integers is sorted correctly by the push_swap
program.
Before running Push_swap, make sure you have the following prerequisites installed:
- macOS or Linux (the project has been tested on macOS and Ubuntu)
- Git
- Clone the repository:
git clone https://github.com/rdoukali42/Push_Swap
- Enter the Push_Swap directory:
cd Push_Swap
- Compile the project:
make
To sort a list of integers, use the following command:
./push_swap 4 2 1 3
Replace 4 2 1 3
with the list of integers you want to sort.
To verify if a list of integers is sorted correctly, use the following command:
./checker 4 2 1 3
Replace 4 2 1 3
with the list of integers you want to check.
The push_swap
program uses the following operations to sort the list:
- sa: Swap the first two elements of stack A.
- sb: Swap the first two elements of stack B.
- ss: sa and sb at the same time.
- pa: Push the first element of stack B to stack A.
- pb: Push the first element of stack A to stack B.
- ra: Rotate stack A (move the first element to the end).
- rb: Rotate stack B (move the first element to the end).
- rr: ra and rb at the same time.
- rra: Reverse rotate stack A (move the last element to the beginning).
- rrb: Reverse rotate stack B (move the last element to the beginning).
- rrr: rra and rrb at the same time.
$ ./push_swap 4 2 1 3
sa
ra
Contributions are welcome! If you find any issues or have suggestions, feel free to open an issue or create a pull request.