Inside this repository, you can see all the code that has been created for the Push Swap project, including the mandatory part and the bonus part.
Write a program that sorts in a ascending order a given list of numbers using predefined movements.
At the beginning you have two stacks (A and B) to use. Stack A must be filled with the given list of numbers and stack B must be empty.
Movement | How it works |
---|---|
pa | Take the first element at the top of B and put it at the top of A. Do nothing if B is empty. |
pb | Take the first element at the top of A and put it at the top of B. Do nothing if A is empty. |
sa | Swap the first 2 elements at the top of stack A. Do nothing if there is only one or no elements. |
sb | Swap the first 2 elements at the top of stack B. Do nothing if there is only one or no elements. |
ss | sa and sb at the same time. |
ra | Shift up all elements of stack A by 1. The first element becomes the last one. |
rb | Shift up all elements of stack B by 1. The first element becomes the last one. |
rr | ra and rb at the same time. |
rra | Shift down all elements of stack A by 1. The last element becomes the first one. |
rrb | Shift down all elements of stack B by 1. The last element becomes the first one. |
rrr | rra and rrb at the same time. |
you can run it with:
$> ./push_swap <list_of_numbers>
It must display the list of instructions used to sort the list of numbers.
Write a checker program to verify if a unsorted list can be sorted with a given list of move instructions.
you can run it with:
$> ./checker <list_of_numbers>
And then you'll have to type the list of move instructions you want the program to execute to sort the numbers,. The movemments are only separated by a new line. Pressing "Ctrl+D" finishes the list of instructions. If the list of numbers passed can be sorted with those instructions it will display "OK", if not, "KO". It can also display "Error" in case you type a nonexistent instruction or a invalid list of number.
Clone this repository in you local computer using a terminal:
$> git clone git@github.com:GiovannaCoqueiro/42cursus-push-swap.git [repository_local]
After cloning the project in your local reposiory you can run some commands you can find in Makefile:
- $> make all: or just make compiles the project
- $> make clean: deletes the object files created during compilation
- $> make fclean: executes the clean command and also deletes the binary created
- $> make re: executes the fclean command followed by the all command
- $> make bonus: compiles the project
- $> make re: executes the fclean command followed by the rebonus command