Code Monkey home page Code Monkey logo

aslanamca / push_swap Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 3.1 MB

This project will make you sort data on a stack, with a limited set of instructions, using the lowest possible number of actions. To succeed you’ll have to manipulate various types of algorithms and choose the one (of many) most appropriate solution for an optimized data sorting.

Makefile 1.90% C 98.10%
42born2code 42school algorithms-and-data-structures c ecole42 make makefile push-swap push-swap-42 push-swap42

push_swap's Introduction

push_swap

This project will make you sort data on a stack, with a limited set of instructions, using the lowest possible number of actions. To succeed you’ll have to manipulate various types of algorithms and choose the one (of many) most appropriate solution for an optimized data sorting.

For more detailed information, look at the subject of this project.

Usage

Requirements

The function is written in C language and thus needs the gcc compiler and some standard C libraries to run.

Instructions

1. Compiling the program

To compile, go to the program path and run:

$ make

2. Executing the program

To execute the program, run:

$ ./push_swap $ARG

where $ARG is a space separated list of integers, e.g. ARG="1 5 2 4 3"

Actions

PUSH

Take the first element at the top of one stack and put it at the top of the other; do nothing if the origin stack is empty.

  • pa - top element of stack b goes to top of stack a.
  • pb - top element of stack a goes to top of stack b.

SWAP

Swap the first 2 elements at the top of the stack; do nothing if there is only one or no elements.

  • sa - swap stack a.
  • sb - swap stack b.
  • ss - sa and sb at the same time.

ROTATE

Shift up all elements of the stack by one; the first element becomes the last.

  • ra - rotate stack a.
  • rb - rotate stack b.
  • rr - ra and rb at the same time.

REVERSE ROTATE

Shift down all elements of the stack by one; the last element becomes the first.

  • rra - reverse rotate stack a.
  • rrb - reverse rotate stack b.
  • rrr - rra and rrb at the same time.

push_swap's People

Contributors

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