Push Swap is a project in the 42 curriculum with the objective of sorting a stack. Due to the structure of the stack, you will need to solve it using specific instructions.
-
pa
andpb
: To sort the stack, you will have a little help in the form of a temporary stack that will be used to store some data to return it back when you finish sorting.pa
: This is used when you want to push some element onto stack A.pb
: This is used when you want to push some element onto stack B.
-
sa
andsb
: These instructions are used to swap the first (the top) element with the second element in the stack.
ra
andrb
: These instructions will rotate the elements, with the first (the top) element becoming the last element in the stack (at the bottom), and the second element becoming the top element in the stack.
rra
andrrb
: These instructions are used to take the last element in the stack and move it to the first position in the stack. The first (the top) element in the stack will become the second element.
You will need to find an algorithm that uses as few instructions as possible. First, you have to understand how the stack works and implement a stack data structure because in C, there is no built-in data structure called "stack."