push_swap is an algorithmic project designed to sort a stack of integers using a limited set of operations.
There are 2 stacks named a and b. The goal is to sort in ascending order numbers into stack a.
-The stack a contains a random amount of negative and/or positive numbers which cannot be duplicated.
-The stack b is empty.
-Available operations with stacks:
-
sa (swap a):
Swaps the first two elements at the top of stacka.
Does nothing if there is only one or no elements. -
sb (swap b):
Swaps the first two elements at the top of stackb.
Does nothing if there is only one or no elements. -
ss:
Performssaandsbsimultaneously. -
pa (push a):
Takes the first element at the top of stackband move it to the top of stacka.
Does nothing if stackbis empty. -
pb (push b):
Takes the first element at the top of stackaand move it to the top of stackb.
Does nothing if stackais empty. -
ra (rotate a):
Shifts all elements of stackaupwards by one position.
The first element becomes the last. -
rb (rotate b):
Shifts all elements of stackbupwards by one position.
The first element becomes the last. -
rr:
Performsraandrbsimultaneously. -
rra (reverse rotate a):
Shifts all elements of stackadownwards by one position.
The last element becomes the first. -
rrb (reverse rotate b):
Shifts all elements of stackbdownwards by one position.
The last element becomes the first. -
rrr:
Performsrraandrrbsimultaneously.
- Clone the repository and compile the program:
git clone git@github.com:shatilovdr/42-push_swap.git
cd 42-push_swap
make- Run the program with a list of integers as arguments:
./push_swap 3 2 5 1 4- Compile the program:
make bonus- Run the program with a list of integers as arguments:
./push_swap 3 2 1 | ./checker 3 2 1