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:
Performssa
andsb
simultaneously. -
pa (push a):
Takes the first element at the top of stackb
and move it to the top of stacka
.
Does nothing if stackb
is empty. -
pb (push b):
Takes the first element at the top of stacka
and move it to the top of stackb
.
Does nothing if stacka
is empty. -
ra (rotate a):
Shifts all elements of stacka
upwards by one position.
The first element becomes the last. -
rb (rotate b):
Shifts all elements of stackb
upwards by one position.
The first element becomes the last. -
rr:
Performsra
andrb
simultaneously. -
rra (reverse rotate a):
Shifts all elements of stacka
downwards by one position.
The last element becomes the first. -
rrb (reverse rotate b):
Shifts all elements of stackb
downwards by one position.
The last element becomes the first. -
rrr:
Performsrra
andrrb
simultaneously.
- 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