Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

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.

Awesome Lists containing this project

README

        

PushSwap















Introduction
Structure
Docs
Cloning
Usage
Norms
Theoretical
Tutorial
Contributors

## 🗣️ Introduction

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.

## 🧬 Project Structure

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.

## 🗃️ Documentation

For detailed documentation, including usage examples and function breakdowns, please visit the link below:





## 🫥 Cloning the Repository

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.

## 🕹️ Compilation and Usage

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

## 📖 Theoretical Background

All the theoretical material used to develop this project is organized and can be accessed directly via the link below:





## 🔬 Tutorial

A step-by-step tutorial is available and can be followed to complete the project. It is linked in the button below.





## 👥 Contributors