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.
![Screen Shot 2023-07-27 at 4 25 54 PM](https://private-user-images.githubusercontent.com/75099354/256567966-6728a357-6ee9-41e8-9203-c51afdce3ccd.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjAyMTQzOTMsIm5iZiI6MTcyMDIxNDA5MywicGF0aCI6Ii83NTA5OTM1NC8yNTY1Njc5NjYtNjcyOGEzNTctNmVlOS00MWU4LTkyMDMtYzUxYWZkY2UzY2NkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MDUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzA1VDIxMTQ1M1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTZlYmU5YWU0NzBiNmM1MDNmMmY2ODc0MzljM2VkZmJiNjQ0ZjFlOTJiODcwOWMxYTJjZGVkNzZmZjI5MjExNGEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.v5xw3PG8mcwl4p8TMFCe0FgIBNJKwpQRyy9xS-hcVbk)