push_swap is a sorting algorithm project where a stack of integers must be sorted using a limited set of operations and two stacks (a and b).
The goal is to minimize the number of operations.
- Sorting using only allowed stack operations
- Optimized for minimal moves
- Handles different input sizes efficiently
- Supports multiple sorting strategies
- Bonus: checker program for validation
- C
- Algorithms
- Data Structures (Stacks)
makeBuild bonus (checker):
make bonusClean files:
make clean
make fclean
make re./push_swap 3 1 2
./push_swap "5 4 3 2 1"Using checker (bonus):
ARG="5 3 1 4 2"
./push_swap $ARG | ./checker $ARGpb
pb
sa
pa
pa
- Small inputs (≤5) → simple sorting (hardcoded logic)
- Medium inputs → chunk-based sorting
- Large inputs → radix sort
The program selects the most efficient algorithm depending on input size.
- 100 numbers → ~500–700 operations
- 500 numbers → ~5000–7000 operations
- parsing – input validation
- operations – stack operations
- algorithms – sorting logic
- utils – helper functions
This project develops problem-solving skills, algorithm optimization, and understanding of low-level data structures.
This project was developed collaboratively with a teammate. We worked together on algorithm design, debugging, and optimization strategies, improving both performance and code quality.
Aghvan Aleksanyan 42 Yerevan Student