Efficient two-stack integer sorting using the Turk Algorithm (C, 100–500 elements, with checker bonus).
push_swap is a 42 school project designed to sort integers with minimal stack operations.
This implementation uses the Turk Algorithm, optimized for medium to large inputs, supporting both positive and negative numbers.
- Moves elements between Stack A and Stack B based on a cost evaluation
- Small subsets are sorted using a simplified deterministic method
- Fully deterministic: same input → same output
- Two-stack sorting (Stack A & B)
- Optimized for 100–500 integers
- Full input validation and error handling
- Bonus: checker program for verification
- Strict memory management and C standard compliance
# Compile the project
make
# Generate 500 random numbers
ARG=$(seq -1000 1000 | shuf -n 500 | tr '\n' ' ')
# Run push_swap and count moves
./push_swap $ARG | wc -l
# Run push_swap with checker
./push_swap $ARG | ./checker $ARG