Giter Site home page Giter Site logo

abouabra / 42-pushswap Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 42 KB

PushSwap is a project that consists of sorting a stack of integers using two stacks and a limited set of operations.

Makefile 6.10% C 93.90%
42 42-push-swap algorithms cprogramming sorting stack

42-pushswap's Introduction

PushSwap

Description

PushSwap is a project that consists of sorting a stack of integers using two stacks and a limited set of operations. The goal is to sort the stack in the least amount of operations. this project is part of the 42 school curriculum. it aims to teach the students how to work with linked lists and to optimize their algorithms.

Project Structure

the project is divided into two programs:

push_swap

  • a program that takes a list of integers as arguments and sorts them using the following operations:
Operation Description
sa Swap the first two elements of stack A
sb Swap the first two elements of stack B
ss sa and sb at the same time
pa Take the first element from stack B and put it on top of stack A
pb Take the first element from stack A and put it on top of stack B
ra Rotate stack A up by one
rb Rotate stack B up by one
rr ra and rb at the same time
rra Rotate stack A down by one
rrb Rotate stack B down by one
rrr rra and rrb at the same time
  • checker: a program that takes a list of integers as arguments and reads a list of operations from the standard input. It then applies the operations to the list of integers and checks if the list is sorted. If the list is sorted, the program prints OK, otherwise it prints KO.

Installation

  1. Clone the repository:
git clone https://github.com/abouabra/42-PushSwap.git
  1. Change the current working directory:
cd 42-PushSwap
  1. Compile the project:
make

Note

if you want to compile the checker program, run the following command:

make bonus

Usage

The program takes a list of integers as arguments and sorts them using the following operations:

To sort a list of integers, run the program with the following command:

./push_swap 4 2 1 3

it will output the list of operations needed to sort the list.

rra
rra
pb
rra
pa

to check if the list is sorted, you can use the checker program:

./push_swap 4 2 1 3 | ./checker 4 2 1 3

it will output OK if the list is sorted, otherwise it will output KO.

Final Note

If you have any suggestions or improvements, feel free to open an issue or submit a pull request.

42-pushswap's People

Contributors

abouabra avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.