Push_swap is a sorting algorithm project at 42 School that involves sorting a stack of integers using only two stacks and a set of predefined operations. The goal of this project is to sort a given stack of integers in ascending order with the lowest number of operations possible.
To compile the push_swap program, navigate to the root directory of the project and run make
. This will compile the push_swap executable.
The push_swap program takes a list of integers as arguments and outputs the list of operations needed to sort the stack in ascending order.
Usage: ./push_swap [list of integers]
Example: ./push_swap 4 67 3 87 23
The operations that can be used are:
sa
swap the first two elements at the top of stack asb
swap the first two elements at the top of stack bss
do sa and sb at the same timepa
take the first element from the top of stack b and put it at the top of stack apb
take the first element from the top of stack a and put it at the top of stack bra
rotate stack a (move the first element to the end of the stack)rb
rotate stack b (move the first element to the end of the stack)rr
do ra and rb at the same timerra
reverse rotate stack a (move the last element to the top of the stack)rrb
reverse rotate stack b (move the last element to the top of the stack)rrr
do rra and rrb at the same time Each operation should be followed by a new line character.
You can find the visualizer I used here