Push Swap is a sorting algorithm challenge where you must sort a stack of integers using a limited set of stack manipulation instructions with minimal operations.
- Two stacks:
aandb - Goal: Sort stack
ain ascending order - Allowed operations:
sa: Swap top two elements of stack asb: Swap top two elements of stack bss: Swap top elements of both stackspa: Push top element from b to apb: Push top element from a to bra: Rotate stack a uprb: Rotate stack b uprr: Rotate both stacks uprra: Reverse rotate stack arrb: Reverse rotate stack brrr: Reverse rotate both stacks
make # Compile push_swap
make bonus # Compile checker (optional)# Sort integers
./push_swap 3 2 1 0 5
# Check sorting with checker
./push_swap 3 2 1 0 5 | ./checker 3 2 1 0 5- 100 numbers: < 700 operations
- 500 numbers: < 5500 operations
- C programming language
- No global variables
- Minimal number of sorting operations
- Error handling for invalid inputs
- Implement efficient sorting algorithm
- Minimize number of stack operations
- Handle edge cases and input validation
- Implement a
checkerprogram to validate sorting instructions
- Mohammed Amine Es-salhi