Give it a list of integers and it prints the shortest sequence of stack operations it can find that sorts them. Written in C, built at 42.
- Every value is replaced by its rank, so the sort only ever deals with
0..N-1. - Up to 5 numbers are handled by hand-written cases.
- Anything larger uses a two-phase chunk sort: push everything to stack
bin chunks so it lands roughly sorted, then pull it back toalargest first, always rotatingbin the cheaper direction.
| Input | Average moves | Worst seen |
|---|---|---|
| 100 random integers | ~660 | ~691 |
| 500 random integers | ~5950 | ~6060 |
make
./push_swap 2 1 3 6 5 8Bad input (non-numbers, duplicates, out-of-range values) prints Error to stderr.