GithubHelp home page GithubHelp logo

simon-zerisenay / 42_push_swap Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 83 KB

Pushswap is a 42 project emphasizing efficient sorting by minimizing operations. Participants use a limited set of commands to manipulate stacks and achieve the desired sorted order, showcasing algorithm design and optimization skills while developing problem-solving abilities.

License: MIT License

Makefile 4.80% C 95.20%
42 42pushswap c chunking cprogramming ecole42 linkedlist midpoint pushswap sorting-algorithms

42_push_swap's Introduction

Push Swap

42 Badge

Score

125

Introduction

GitHub code size in bytes Number of lines of code Code language count GitHub top language GitHub last commit

Welcome to the Push Swap project! This project is part of the curriculum at 42 and focuses on sorting algorithms and the manipulation of stack data structures. Push Swap involves creating two programs: one that sorts a stack of integers using a specific set of operations, and another that checks if the given set of instructions properly sorts the stack.

Objective

The main objective of the Push Swap project is to develop efficient sorting algorithms that can arrange a stack of integers in ascending order using a limited set of operations. Additionally, you are required to implement a checker program that verifies if a given set of instructions correctly sorts the stack.

Features

Sorting Algorithm Push Swap allows you to implement different sorting algorithms to arrange the stack of integers. For this project, a custom algorithm is commonly used for optimal performance:

Midpoint Algorithm: This algorithm assigns indexes to the numbers based on their order in the stack. It then calculates the midpoint by adding the indexes and finding the mean. The algorithm repeatedly sends all the numbers with indexes lower than the midpoint to stack B. This process is repeated until only 3 numbers are left on stack A. The 3 remaining numbers are used as a reference to push back from stack B to stack A. The algorithm calculates the cost of each operation and undertakes the cheapest one to minimize the number of moves required. By utilizing this custom algorithm, you can achieve efficient sorting with a reduced number of operations.

Stack Manipulation

The project requires manipulating two stacks, stack A and stack B, using a set of predefined operations:

sa/sb: Swap the top two elements of stack A/B. ss: Perform both sa and sb. pa/pb: Push the top element from stack B/A onto stack A/B. ra/rb: Rotate the stack A/B by moving the top element to the bottom. rr: Perform both ra and rb. rra/rrb: Reverse rotate the stack A/B by moving the bottom element to the top. rrr: Perform both rra and rrb. These operations allow you to rearrange the elements in the stacks and ultimately sort the integers.

Checker Program

In addition to the sorting program, you are required to create a checker program. The checker program takes a list of instructions and verifies if executing those instructions on the stack correctly sorts the integers. It displays "OK" if the stack is sorted after executing the instructions and "KO" otherwise.

Installation and Usage

To install and run the Push Swap project, follow these steps:

Clone the project repository:

			git clone https://github.com/your_username/42-push_swap.git

Navigate to the project directory:

					cd 42-push_swap

Compile the project using the provided Makefile:

			     		   make

Sort the integers using the push_swap program:

		./push_swap <Enter as many numbers as you want but separated by space>

Verify the sorting using the checker program:

				  ./checker <list_of_integers>

Ensure that you have the necessary libraries and dependencies installed on your system. The project's repository may provide further instructions on any additional requirements.

Testing

To test the Push Swap project and validate its functionality, follow these steps:

Generate a random set of integers using the provided generate.sh script. Sort the generated integers using the push_swap program. Execute the obtained instructions on the stack using the checker program. Verify that the checker program displays "OK" if the stack is sorted correctly. Test the project with various sets of integers

42_push_swap's People

Contributors

simon-zerisenay avatar

Stargazers

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