Skip to content

mohos26/push_swap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

push_swap

📘 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])


📌 Table of Contents

  • About
  • Features
  • Requirements
  • Installation
  • Usage
  • Project Structure
  • Makefile Rules
  • Contributing

🧠 About

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])


⭐ Features

✔️ Sorts integers using two stack data structures ✔️ Supports the full instruction set required by the project:

  • sa, sb, ss
  • pa, pb
  • ra, rb, rr
  • rra, rrb, rrr ✔️ Efficient algorithm aimed at minimizing operations ✔️ Optional checker program (bonus) to validate sequences of operations (if implemented) ([GitHub][2])

📋 Requirements

Before you begin, make sure you have:

  • A C compiler (gcc, clang, etc.)
  • make
  • A POSIX‑compatible environment (Linux / macOS / WSL)

📦 Installation

  1. Clone the repository:

    git clone https://github.com/mohos26/push_swap.git
    cd push_swap
  2. Compile the project:

    make

    This should compile the source code and create the push_swap executable.


📖 Usage

To sort a set of integers, run:

./push_swap <list of integers>

Example:

./push_swap 8 3 5 2 9 1

This will print a list of operations on stdout that, when applied, sort the list in ascending order. ([GitHub][1])


📌 Bonus — Checker

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 1

checker should print OK if the sequence sorts correctly, or KO otherwise. ([GitHub][2])


📂 Project Structure

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])

🛠 Makefile Rules

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

🤝 Contributing

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors