An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          


Link-Wolf - push_swap
42 grade - 121 / 100
Year - 2022
stars - push_swap
forks - push_swap
issues - push_swap
OS - macOS





Logo

Push_swap


Because Swap_push isn’t as natural

Optimized data sorting on stacks




Report Bug
·
Request Feature


Table of Contents



  1. About The Project


  2. Getting Started


  3. Usage

  4. Roadmap

  5. Contributing

## About The Project




push_swap illustration


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

(back to top)

## 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
```

(back to top)

## 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_

(back to top)

## 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).

(back to top)

## 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

(back to top)