Score: WIP/100
Finished: ??.??.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.git
git clone https://github.com/blueyaGIT/push_swap.git
gh repo clone blueyaGIT/push_swap
This will create a directory called push_swap/
. Enter it with the command:
cd push_swap
To compile the program, run:
make
This will generate the push_swap
executable.
Execute the program with a list of integers:
./push_swap 4 67 3 87 23
The 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 stackB
to stackA
.pb
- Push the top element from stackA
to stackB
.ra
- Rotate stackA
upwards.rb
- Rotate stackB
upwards.rr
- Rotate both stacks upwards.rra
- Reverse rotate stackA
.rrb
- Reverse rotate stackB
.rrr
- Reverse rotate both stacks.
main.c
- Main logic of the program.stack_control*.c
- Contains all stack operations.algorithm*.c
- Implements sorting algorithms.utils*.c
- Utility functions for handling stacks and arguments.push_swap.h
- Header file with function prototypes.Makefile
- Automates compilation.
- 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.