Skip to content

A program that sorts numbers in ascending order as fast as possible using two stacks and a handful of operations. A 42 Cursus project.

Notifications You must be signed in to change notification settings

RushMaverick/push_swap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

push_swap

rrask's 42 push_swap Score

This project aims to increase one's knowledge of complexity in programming. Push_swap figures out what are the optimal moves to get any number of digits sorted. This is done through an implementation of the radix sort algorithm and pre-sorting.

Radix sort sorts the numbers based on their binary representation from right to left. The algorithm repeatedly performs operations on the stack until the numbers are sorted. The code includes functions for stack manipulation. Keep in mind this is but one of many algorithms, and might not be the optimal solution for getting the right set of instructions.

Links

Radix Sorting

push_swap explanation in detail (Props to Leo Fu)

push_swap_visualizer

Run Locally

Clone the project

  git clone https://github.com/RushMaverick/push_swap.git

Go to the project directory

  cd push_swap

Make the program

  make

Run the program

  ./push_swap 23 42 12 4 -2

You can input any numbers you want. If there are duplicates (two 2's for example.) it will say error.

The output will be what moves are required to sort the given numbers.

Moves

The following are the moves that were allowed for moving things within the stack.

Move Functionality
Swap Swaps the two first elements of the given stack.
Move Functionality
Push Pushes the first element of the given stack to the top of the other given stack.
Move Functionality
Rotate Rotates the top of the given stack to the stack's bottom.
Move Functionality
Reverse Rotate Rotates the bottom of the given stack to the stack's top.
Move Functionality
Rotate Both Performs rotate on both stacks.
Move Functionality
Swap Both Performs swap on both stacks.

About

A program that sorts numbers in ascending order as fast as possible using two stacks and a handful of operations. A 42 Cursus project.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published