Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/vinicius-santoro/42-formation-lvl2-7.push-swap

Project 7: Push Swap - Seventh project for the formation of software engineers at school 42 São Paulo.
https://github.com/vinicius-santoro/42-formation-lvl2-7.push-swap

Last synced: 16 days ago
JSON representation

Project 7: Push Swap - Seventh project for the formation of software engineers at school 42 São Paulo.

Awesome Lists containing this project

README

        

# 42-formation-lvl2-7.push-swap

### _Project 7: Push Swap - Seventh project for the formation of software engineers at school 42 São Paulo._

- This project aim to sort data on a stack, with a limited set of instructions, using the lowest possible number of operations.

## _This project was like this:_

![push_swap](https://user-images.githubusercontent.com/83036509/163658386-4b62a6f3-13d3-4a1b-be12-c2e37d695f37.gif)

## _The operations we can use are:_

| Operation | Description |
|-----------------------|-------------------------------------------------------------------|
| sa (swap a) | Swap the first 2 elements at the top of stack a |
| sb (swap b) | Swap the first 2 elements at the top of stack b |
| pa (push a) | Take the first element at the top of b and put it at the top of a |
| pb (push b) | Take the first element at the top of a and put it at the top of b |
| ra (rotate a) | Shift up all elements of stack a by 1 |
| rb (rotate b) | Shift up all elements of stack b by 1 |
| rr | ra and rb at the same time |
| rra (reverse rotate a)| Unsigned hexadecimal integer (uppercase) |
| rrb (reverse rotate b)| Shift down all elements of stack b by 1 |
| rrr | rra and rrb at the same time. |

## _How to test it_

To test, you should run the Make all command

```bash
make all
```

Now compile the executable file generated by the makefile and add the parameters you want. For example:

```bash
./push_swap 42 142 9123 -123 -254231278 -10470 12748 -15027 -17306 1864
```

## _Examples_

We can check stacks A and B. On the right, we can see the operation that was used.

Example 1) Sorting with 5 random and distinct integers:

![sorting-5](https://user-images.githubusercontent.com/83036509/163658759-5aff900e-a2b8-4dcb-9eb5-3d5a5f3b88cc.gif)

Example 2) Sorting with 100 random and distinct integers:

https://user-images.githubusercontent.com/83036509/163659156-83326c8f-b6cb-4462-bf9b-5f05fa954f8f.mp4

Example 3) Sorting with 1000 random and distinct integers:

https://user-images.githubusercontent.com/83036509/163659396-9e4568e9-8f19-4cdb-9dba-42c2922cac6a.mp4