Giter VIP home page Giter VIP logo

push_swap's Introduction

push_swap

push_swap is a project developed for 42 Heilbroon School.

Keywords

C programming - sorting algorithm - time complexity - data structure - abstract data type - stack - LIFO - circular linked lists - radix sort - mapping

Subject

The goal of this project is to efficiently sort a given set of integers in ascending order using 2 stacks as Abstract Data Types, while minimizing the number of operations. For more info about the requirements, take a look at the subject contained in this repo.

Brief Explanation

The code can be divided into three main sections:

1. Input Parsing

Ensure the consistency of the input through meticulous validation functions. The project requirements specify that duplicates are not allowed. If the input is invalid at any step, the allocated memory is freed, and an error is returned.

2. Data Structure & Operations

I implemented circular linked lists to handle the list of integers. To fulfill the project requirements, the following operations are implemented: pop, push, rotate (shift up), reverse rotate (shift down), and swap of two elements. These operations serve as the foundation to sort the integers.

3. Adapting a Sorting Algorithm

In adapting the sorting algorithm for this project, I have chosen to implement the Radix Sort algorithm. To optimize the sorting process while staying within the constraints of the 2-stack requirement, I used bitwise operations and developed an indexing-based mapping approach.

4. Leaks free

Like in any other project of 42, the memory allocated by malloc() has to be properly sfreed. No leaks are tolerated. In this project I checked the leaks using valgrind and system("leaks <program-name>")


Try it out

  1. Clone the repository:
git clone [email protected]:NicoCastelnuovo/push_swap.git push_swap
  1. Navigate to the push_swap directory and make program:
cd push_swap
make
  1. Execute it, passing a random amount of number:
./push_swap <random-numbers>
  1. Accordingly on the input you choose, the program should either throw an error in case of invalid arguments, print the moves to sort the numbers or nothing if the numbers are already sorted.

Note: Since it's not specified by the subject, the sorted numbers are not explicitely printed.

push_swap's People

Contributors

ncasteln avatar

Stargazers

 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.