📘 push_swap is a C program that orders a list of integers using two stacks and a limited set of operations. This project is part of the 42 School curriculum and focuses on mastering algorithm design, stack manipulation, and optimization under constraints. ([GitHub][1])
- About
- Features
- Requirements
- Installation
- Usage
- Project Structure
- Makefile Rules
- Contributing
push_swap outputs a sequence of operations that, when applied, will sort an array of integers in ascending order using only two stacks (A and B) and specific operations like swap, push, rotate, and reverse rotate. The goal is to use the fewest possible moves. ([GitHub][1])
✔️ Sorts integers using two stack data structures ✔️ Supports the full instruction set required by the project:
sa,sb,sspa,pbra,rb,rrrra,rrb,rrr✔️ Efficient algorithm aimed at minimizing operations ✔️ Optional checker program (bonus) to validate sequences of operations (if implemented) ([GitHub][2])
Before you begin, make sure you have:
- A C compiler (
gcc,clang, etc.) make- A POSIX‑compatible environment (Linux / macOS / WSL)
-
Clone the repository:
git clone https://github.com/mohos26/push_swap.git cd push_swap -
Compile the project:
make
This should compile the source code and create the
push_swapexecutable.
To sort a set of integers, run:
./push_swap <list of integers>Example:
./push_swap 8 3 5 2 9 1This will print a list of operations on stdout that, when applied, sort the list in ascending order. ([GitHub][1])
If you’ve implemented a checker program (common bonus requirement), you can validate the operations:
./push_swap 8 3 5 2 9 1 | ./checker 8 3 5 2 9 1checker should print OK if the sequence sorts correctly, or KO otherwise. ([GitHub][2])
push_swap/
├── srcs/ # Source code (sorting logic, operations)
├── includes/ # Header files
├── bonus/ # Bonus features (e.g., checker)
├── Makefile # Build rules
├── push_swap.h # Main project header
├── checker.h # Checker header (if implemented)
├── .gitignore
└── ...
Typical modules include:
- Argument parsing and validation
- Stack operation implementations
- Sorting strategy and algorithm
- Helpers (utilities, error handling) ([GitHub][1])
| Rule | Description |
|---|---|
make |
Compile push_swap |
make bonus |
Compile push_swap and checker (if bonus implemented) |
make clean |
Remove object files (*.o) |
make fclean |
Remove object files and executables |
make re |
Rebuild everything from scratch |
This repository contains your personal implementation of the push_swap project. If you’d like to:
- Add example scripts
- Provide test cases
- Improve documentation
feel free to open a pull request.