push_swap is a project from the 42 cursus that involves creating a program to sort a stack of integers using a limited set of operations. The main objective is to understand and implement various sorting algorithms and to optimize them for performance and efficiency within the constraints of the project.
To compile and run the project, you will need:
- A Unix operating system (Linux or macOS).
- gcc or any C compiler.
- Make.
Clone the project repository and navigate to the main directory:
git clone https://github.com/PaLucena/push_swap.git
cd push_swap
Compile the project using the included Makefile:
make
This will generate the push_swap
executable in the current directory.
To sort a stack of integers, run the following command:
./push_swap <list_of_integers>
Where <list_of_integers>
is a list of space-separated integers.
Example:
./push_swap 3 2 5 1 4
The push_swap program supports the following operations to sort the stack:
sa
: Swap the first two elements at the top of stack A.sb
: Swap the first two elements at the top of stack B.ss
: Swap the first two elements at the top of both stacks A and B.pa
: Push the top element of stack B onto stack A.pb
: Push the top element of stack A onto stack B.ra
: Rotate stack A upwards (first element becomes the last one).rb
: Rotate stack B upwards (first element becomes the last one).rr
: Rotate both stacks A and B upwards.rra
: Reverse rotate stack A (last element becomes the first one).rrb
: Reverse rotate stack B (last element becomes the first one).rrr
: Reverse rotate both stacks A and B.
The project is organized into the following files and directories:
src/
: Contains the source code of the sorting algorithms and operations.include/
: Contains the header files.Makefile
: Build script to generate the executable.README.md
: Project documentation.
This project is licensed under the MIT License. See the LICENSE
file for more details.