Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pin3dev/42_pushswap
Algorithm challenge focused on sorting a stack of integers with the minimum number of operations. Implemented in C with a limited set of operations, ideal for understanding algorithm optimization.
https://github.com/pin3dev/42_pushswap
42cursus 42porto 42pushswap 42school algorithm c sorting sorting-algorithm sorting-algorithms tutorial tutorial-sourcecode
Last synced: about 2 months ago
JSON representation
Algorithm challenge focused on sorting a stack of integers with the minimum number of operations. Implemented in C with a limited set of operations, ideal for understanding algorithm optimization.
- Host: GitHub
- URL: https://github.com/pin3dev/42_pushswap
- Owner: pin3dev
- License: mit
- Created: 2023-05-04T09:54:48.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-24T23:57:50.000Z (4 months ago)
- Last Synced: 2024-11-05T20:17:11.219Z (3 months ago)
- Topics: 42cursus, 42porto, 42pushswap, 42school, algorithm, c, sorting, sorting-algorithm, sorting-algorithms, tutorial, tutorial-sourcecode
- Language: C
- Homepage:
- Size: 7.23 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
PushSwap
![]()
![]()
Introduction •
Structure •
Docs •
Cloning •
Usage •
Norms •
Theoretical •
Tutorial •
Contributors
The **Push Swap** project is an algorithm challenge aimed at sorting a stack of integers in the least number of moves, using a constrained set of operations. This project serves as a way to deepen understanding of sorting algorithms and optimize problem-solving techniques.
This repository is dedicated to the implementation of an efficient solution to sort the stack using the minimum number of operations. The project does not include a checker, so the validation must be done with external tools or the checker provided by 42.
The **Push Swap** project is organized into different components based on the operations allowed to manipulate two stacks (A and B). The mandatory part includes creating algorithms to sort small to large sequences using the following operations:
- **`sa`**, **`sb`**, **`ss`**: Swap operations on stack A, stack B, or both.
- **`pa`**, **`pb`**: Push operations to move the top element from one stack to another.
- **`ra`**, **`rb`**, **`rr`**: Rotate operations to move the top element to the bottom.
- **`rra`**, **`rrb`**, **`rrr`**: Reverse rotate operations to move the bottom element to the top.The project is focused on optimization and efficiency, aiming to minimize the number of moves for different stack sizes.
For detailed documentation, including usage examples and function breakdowns, please visit the link below:
To clone this repository and compile the project, run the following commands:
```bash
git clone https://github.com/pin3dev/42_Push_Swap.git
cd 42_Push_Swap/pushswap
```
This will download the project from GitHub into your local machine. Once inside the `42_Push_Swap` directory, you can compile the project using the provided Makefile.### Makefile
A `Makefile` is provided to simplify the compilation process. The Makefile includes the following rules:
- `all`: Compiles the project.
- `clean`: Removes object files.
- `fclean`: Removes object files and the executable.
- `re`: Recompiles the entire project from scratch.To compile the project, simply run:
```bash
make
```
This will generate the `push_swap` executable, which can be used to sort a list of integers.### Basic Usage
To run the **Push Swap** algorithm on a list of integers:
1. Execute the program with a set of integers as arguments:
```bash
./push_swap 3 5 2 1 4
```2. The program will output a sequence of operations needed to sort the integers:
```bash
pb
pb
sa
pa
rra
pa
rra
rra
```You can also test the number of operations by piping the output to `wc -l`:
```bash
./push_swap 3 5 2 1 4 | wc -l
```## ⚠️ Norms and Guidelines Disclaimer
This project strictly follows the [**42 School Norm**](https://github.com/pin3dev/42_Cursus/blob/b9cd0fe844ddb441d0b3efb98abcee92aee49535/assets/General/norme.en.pdf) coding guidelines, which significantly influenced certain decisions in its implementation. These rules may sometimes lead to seemingly inefficient or unusual solutions, but they were necessary to meet the strict requirements of the school.
All the theoretical material used to develop this project is organized and can be accessed directly via the link below:
A step-by-step tutorial is available and can be followed to complete the project. It is linked in the button below.