Push_swap is a function that sorts in ascending order a stack (stack a) using a temporal stack (stack b).
- sa: Swaps the first two elements at the top of stack a.
- sb: Swaps the first two elements at the top of stack b.
- ss: Does sa and sb at the same time.
- pa: If stack b is not empty, puts the first element at the top into stack a.
- pb: If stack a is not empty, puts the first element at the top into stack b.
- ra: Shifts up all elements of stack a by 1. So the first element becomes the last one.
- rb: Shifts up all elements of stack b by 1. So the first element becomes the last one.
- rr: Does ra and rb at the same time.
- rra: Shifts down all elements of stack a by 1. So the last element becomes the first one.
- rrb: Shifts down all elements of stack b by 1. So the last element becomes the first one.
- rrr: Does rra and rrb at the same time.
The goal is to sort the stack in the lowest amount of operations possible.
Clone and compile the project
git clone https://github.com/ribana-b/push_swap.git
cd push_swap
make
Execute the program
./bin/push_swap <args>
./bin/push_swap 5 3 2
./bin/push_swap "3 1" "5 6" "2 7"
./bin/push_swap "2915" 1258 "98123 -1 -2 -3"
The goal of the bonus is to replicate the behaviour of the given checker for push_swap.
Compile the bonus part
make bonus
Alternatively
cd checker_bonus
make
Execute the program
./checker_bonus/bin/checker <args>
Then you have to introduce the movements and press Ctrl + D when you are finished.
Additionally, you can pipe the output of push_swap
./bin/push_swap <args> | ./checker_bonus/bin/checker <args>
Note
args
must be the same for both push_swap
and checker
.
./checker_bonus/bin/checker 5 3 2 << EOF
sa
rra
EOF
./bin/push_swap 25 30 1 -1 | ./checker_bonus/bin/checker 25 30 1 -1
- Random Number Generator: https://www.random.org/integer-sets/
If you want to check my progress as a student in 42 Málaga check out my main repository!