https://github.com/0bvim/push_swap
This project will make you sort data on a stack, with a limited set of instructions, using
https://github.com/0bvim/push_swap
Last synced: about 1 year ago
JSON representation
This project will make you sort data on a stack, with a limited set of instructions, using
- Host: GitHub
- URL: https://github.com/0bvim/push_swap
- Owner: 0bvim
- License: mit
- Created: 2023-11-14T06:34:20.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-27T14:25:04.000Z (about 2 years ago)
- Last Synced: 2025-02-13T16:42:35.659Z (over 1 year ago)
- Language: C
- Size: 997 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

[](README.md) [](README.pt-BR.md)
# push_swap
This project will make you sort data on a stack, with a limited set of instructions, using
the lowest possible number of actions. To succeed you’ll have to manipulate various
types of algorithms and choose the most appropriate solution (out of many) for an
optimized data sorting.
| Instruction | Description |
|:-----------:|-------------|
| sa | swaps the first and second elements of stack A |
| sb | swaps the first and second elements of stack B |
| ss | executes the sa and sb commands simultaneously |
| pa | removes the first element from stack B and places it on top of stack A |
| pb | removes the first element from stack A and places it on top of stack B |
| ra | rotates stack A from top to bottom |
| rb | rotates stack B from top to bottom |
| rr | rotates both stacks A and B from top to bottom |
| rra | rotates stack A from bottom to top |
| rrb | rotates stack B from bottom to top |
| rrr | rotates both stacks A and B from bottom to top |
#
### Discription of mandatory part
In this part we need to sort a list of numbers given in command line.
```bash
$> ./push_swap 5 3 2 1 4 # sorted list 1 2 3 4 5
```
Another example
```bash
$> ./push_swap -100 -145 150 10 5 300 # sorted list -145 -100 5 10 300
```
We need to handle errors too, because our program only works with unique numbers, no letter or special characters.
### Discription of bonus part
We need to create a program called 'checker'. This program check whether the list of istructions generated by the push_swap program actually sort the stack properly.
```bash
$>./checker 3 2 1 0
rra
pb
sa
rra
pa
OK # show 'OK' if list was sorted properly
$>./checker 3 2 1 0
sa
rra
pb
KO # show 'KO' if it's unsorted.
$>./checker 3 2 one 0
Error # when are not only numbers in args.
$>./checker "" 1
Error # when have empty string or invalid args
```
## Download
### ssh
```ssh
git clone git@github.com:vinicius-f-pereira/push_swap.git
```
### https
```bash
git clone https://github.com/vinicius-f-pereira/push_swap.git
```
### github cli (gh)
```bash
gh repo clone vinicius-f-pereira/push_swap
```
Use `make` or `make bonus` and follow instructions [`Here`](#discription-of-mandatory-part)