https://github.com/link-wolf/push_swap
42 project - Program to sort stacks with only a few operation in an optimal way
https://github.com/link-wolf/push_swap
42 42born2code 42school c macos
Last synced: 2 months ago
JSON representation
42 project - Program to sort stacks with only a few operation in an optimal way
- Host: GitHub
- URL: https://github.com/link-wolf/push_swap
- Owner: Link-Wolf
- Created: 2022-03-17T06:48:41.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-10-01T14:28:15.000Z (almost 2 years ago)
- Last Synced: 2025-01-27T12:49:41.959Z (over 1 year ago)
- Topics: 42, 42born2code, 42school, c, macos
- Language: C
- Homepage:
- Size: 31.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Push_swap
Because Swap_push isn’t as natural
Optimized data sorting on stacks
Report Bug
·
Request Feature
Table of Contents
## About The Project
This project is a very simple and highly effective algorithm project: data will
need to be sorted.
We have at our disposal, 2 stacks (`a` and `b`), a set of int values without duplicates that will be initialized in the stack `a`, and a set of instructions to manipulate both stacks :
- `ra` / `rb` rotates either `a` or `b`
- `rra` / `rrb` rotates either `a` or `b` but in the other direction
- `rr` / `rrr` rotates both `a` and `b` in one direction or the other
- `pa` pushes the top element of `b` to `a`
- `pb` pushes the top element of `a` to `b`
- `sa` / `sb` switches the two top elements of `a` / `b`
- `ss` switches the two top elements of both `a` and `b`
The program should then print in the terminal all the instructions to sort the int values into the stack `a`, by using the stack `b`
The evaluation is made according to the performance of the program (how many operations the program print to sort the stack `a`)
### Bonus features
Make a "Checker" which will get as an argument the stack `a` formatted as a list of integers (in the same way as the push_swap program)
The program will then wait and read instructions on the standard input.
Once all the instructions have been read, the checker will execute them on the stack received as an argument and print `OK` only if the stack `a` is correctly sorted, `KO` otherwise.
We can call the push_swap program then pipe `|` the checker with the same arguments to verify if our push_swap works as intended
## Getting Started
Because it's a simple C program, there isn't much to say here
### Prerequisites
Having a C compiler like cc, gcc or clang
### Installation
1. Clone the repo
```sh
git clone https://github.com/Link-Wolf/push_swap.git
```
2. Compile push_swap
```sh
cd push_swap; make
```
3. Execute the program with a list of integers as a parameter / multiples parameters
```sh
./push_swap "5 648 1 36 -1 98 -364 0"
```
or
```sh
./push_swap 5 648 1 36 -1 98 -364 0
```
## Usage
Test this push_swap with the integers you want, and with as many you want !
#### Push swap program
```sh
./push_swap "5 1 -1 -3 0"
```
#### Possible output
```
pb
pb
sa
pa
ra
pa
ra
```
#### Checker program
```sh
./push_swap "5 1 -1 -3 0" | ./checker "5 1 -1 -3 0"
```
#### Output
```
OK
```
_The checker will print `Error` if one of the given instructions does not exist_
## Roadmap
- [x] Add the checker
- [x] Add back to top links
See the [open issues](https://github.com/Link-Wolf/push_swap/issues) for a full list of proposed features (and known issues).
## Contributing
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
Don't forget to give the project a star! Thanks again!
1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the Branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request