getnextline | ||
libft | ||
printf | ||
src | ||
tests | ||
visualizer | ||
.gitignore | ||
LICENSE | ||
Makefile | ||
push_swap.h | ||
Readme.md | ||
test.sh |
Push Swap
Push Swap is a 2 stack sorting algoritm, The goal is to sort the input in as few moves as possible
I wrote my own algoritm which is a combination of quick sort and bubble sort as radix is very bad with only 2 stacks
The following is a list of the moves we are allowed to make
Move | Description |
---|---|
pa | Pushes the top number from stack B to stack A |
pb | Pushes the top number from stack A to stack B |
sa | Swaps the top 2 numbers in stack A |
sb | Swaps the top 2 numbers in stack B |
ss | Swaps the top 2 numbers in stack A and in Stack B |
ra | Rotates Stack A moves all items forward so the last item becomes the first |
rb | Rotates Stack B moves all items forward so the last item becomes the first |
rr | Rotates Both stacks moves all items forward, so the last item becomes the first |
rra | Reverse Rotates Stack A moves all items backwards, so the first item becomes the last |
rrb | Reverse Rotates Stack B moves all items backwards, so the first item becomes the last |
rrr | Reverse Rotates Both stacks moves all items backwards, so the first item becomes the last |
Improvements
Improve 5 numbers algoritm
simply hardcode all possibilities with 5 numbers or less
Improve more than 30 algoritm
Gotta figure this out to always stay under the goals
Usage
Sorter
- Simply clone or download the repository
- Run
make
in the cloned directory - Start the program with
./push_swap [numbers seperated by space]
- It will return the list of moves to sort the stack
Checker
- Simply clone or download the repository
- Run
make bonus
in the cloned directory - Start the program with
./checker [numbers seperated by space]
- You will have to input moves seperated by a return and when you are done press CTRL + D
- It will return a OK or a KO.
Both
- You can also run both programs with
./push_swap [numbers] | ./checker [same numbers]
Tester
Todo
- test "-" as argument
- check for -Wall -Werror -Wextra
Usage
- Download test.sh to your push swap directory
- Make the file executable
chmod +x test.sh
- Run
./test.sh
to start the test