Push_swap is a sorting algorithm project at 42, where the goal is to sort a stack of integers in ascending order using two stacks (A and B) and a set of predefined operations.
The project focuses on optimizing the sorting process by using a limited set of operations (swap, push, rotate, and reverse rotate) to move elements between stacks effectively.
- Clone the repository:
git clone https://github.com/cj4ck/42-push_swap.git
cd 42-push_swap
- Compile the program:
make
- Run the program with a list of integers:
./push_swap 4 2 9 1 5
- You can use the checker program to validate if the output of the push_swap program correctly sorts the integers:
./push_swap 4 2 9 1 5 | ./checker 4 2 9 1 5
The following operations are available for sorting the stacks:
sa:
Swap the first two elements in stack A.
sb:
Swap the first two elements in stack B.
ss:
Swap the first two elements in both stack A and stack B.
pa:
Push the top element from stack B to stack A.
pb:
Push the top element from stack A to stack B.
ra:
Rotate stack A by moving the top element to the bottom.
rb:
Rotate stack B by moving the top element to the bottom.
rr:
Rotate both stack A and stack B simultaneously.
rra:
Reverse rotate stack A by moving the bottom element to the top.
rrb:
Reverse rotate stack B by moving the bottom element to the top.
rrr:
Reverse rotate both stack A and stack B simultaneously.