2023-03-11 04:22:12 +01:00
|
|
|
# Project Name
|
|
|
|
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
|
2023-03-01 04:36:58 +01:00
|
|
|
|
2023-03-11 04:22:12 +01:00
|
|
|
| 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
|
|
|
|
1. Simply clone or download the repository
|
|
|
|
2. Run `make` in the cloned directory
|
|
|
|
3. Start the program with `./push_swap [numbers seperated by space]`
|
|
|
|
4. It will return the list of moves to sort the stack
|
|
|
|
#### Checker
|
|
|
|
1. Simply clone or download the repository
|
|
|
|
2. Run `make bonus` in the cloned directory
|
|
|
|
3. Start the program with `./checker [numbers seperated by space]`
|
|
|
|
4. You will have to input moves seperated by a return and when you are done press CTRL + D
|
|
|
|
5. It will return a OK or a KO.
|
|
|
|
#### Both
|
|
|
|
1. You can also run both programs with `./push_swap [numbers] | ./checker [same numbers]`
|
|
|
|
|
|
|
|
---
|
|
|
|
## Tester
|
2023-03-11 04:37:20 +01:00
|
|
|
#### Todo
|
|
|
|
- test "-" as argument
|
2023-03-11 04:22:12 +01:00
|
|
|
- check for -Wall -Werror -Wextra
|
|
|
|
|
|
|
|
#### Usage
|
|
|
|
1. Download test.sh to your push swap directory
|
|
|
|
2. Make the file executable `chmod +x test.sh`
|
|
|
|
3. Run `./test.sh` to start the test
|
|
|
|
|
|
|
|
---
|
|
|
|
[This project is part of the studies at 42](https://42.fr/en/homepage/)
|