Giter Club home page Giter Club logo

push_swap's Introduction

push_swap is a 42 school project written in C that aims to sort stacks of integers using a limited set of operations. The project involves implementing an efficient sorting algorithm and optimizing it to minimize the number of operations performed.

Overview

push_swap takes as input two stacks, labeled A and B, each containing a random set of integers. The goal is to sort stack A in ascending order using the following operations:

  • sa: Swap the first two elements of stack A.
  • sb: Swap the first two elements of stack B.
  • ss: Swap the first two elements of both stack A and stack B simultaneously.
  • pa: Push the first element of stack B onto stack A.
  • pb: Push the first element of stack A onto stack B.
  • ra: Rotate stack A upwards, shifting all elements by one position.
  • rb: Rotate stack B upwards, shifting all elements by one position.
  • rr: Rotate both stack A and stack B upwards simultaneously.
  • rra: Rotate stack A downwards, shifting all elements by one position.
  • rrb: Rotate stack B downwards, shifting all elements by one position.
  • rrr: Rotate both stack A and stack B downwards simultaneously.

Functionality:

Key features of push_swap include:

  • Sorting algorithm: Implementation of an efficient sorting algorithm that minimizes the number of operations required to sort the stack.
  • Optimization: Optimization techniques to reduce the number of operations performed, resulting in faster sorting times.
  • Error handling: Robust error handling to detect and handle various error conditions, such as invalid input or memory allocation failures.

Usage

Compile with make

Execute the program with a list of integers, like this:

input: ./push_swap <list_of_integers>

Examples

$> ./push_swap 4 67 2 8 13

This command will sort the integers 4, 67, 2, 8, and 13 using the push_swap algorithm.

push_swap's People

Contributors

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