Push Swap

C

A stack-sorting program that uses a cost-based greedy algorithm to sort integers in as few operations as possible.

View on GitHub
A visualisation of push_swap sorting a stack of integers

Animation via the third-party push_swap_visualizer, not part of the repository.

A program that sorts a stack of integers using only a small, fixed set of stack operations, while trying to use as few operations as possible. The numbers start on stack a with an empty stack b, and the goal is to end with a sorted in ascending order. The only permitted moves are swap, push between stacks, and rotate, so the challenge is not whether the stack can be sorted but how cheaply.

← All projects