42 Urduliz — Common Core project
Sorts a stack of integers using the minimum number of operations with only two stacks (a and b) and a limited set of instructions.
| Op | Description |
|---|---|
sa / sb |
Swap top two elements of stack a/b |
pa / pb |
Push top of b to a / top of a to b |
ra / rb |
Rotate stack a/b upward |
rra / rrb |
Reverse rotate stack a/b |
ss / rr / rrr |
Combined operations |
make
./push_swap 5 2 8 1 3Check with the included tester:
python3 tester.pyUses a quicksort-based approach with optimization for small sets (≤5 elements handled with hardcoded optimal paths). For larger sets, recursively partitions using a pivot and moves chunks between stacks.
Performance targets:
- 3 numbers: ≤ 3 ops
- 5 numbers: ≤ 12 ops
- 100 numbers: ≤ 700 ops
- 500 numbers: ≤ 5500 ops
push_swap/
├── algorithm/ # Quicksort and final sort logic
├── actions/ # push, swap, rotate, reverse_rotate
├── core/ # Argument validation, stack creation
├── utils/ # Free, atoi, helpers
├── printf/ # Embedded ft_printf
├── push_swap.h
└── Makefile
C Algorithms Data Structures Stack Sorting Optimization
This repository is shared for educational and portfolio purposes only.
For 42 students:
- Do not copy this code for your own project submissions
- Use it as a reference to understand concepts and approaches
- Write your own original solution — that is the only way to actually learn
42's core values are learning through practice, peer collaboration, and genuine problem-solving.
MIT — see LICENSE for details. Copyright (c) 2026 Eneko Muñoz Bordona