Skip to content

sort data on a stack, with a limited set of instructions, using the lowest possible number of actions

Notifications You must be signed in to change notification settings

zainabdnaya/Push_Swap_42

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 

Repository files navigation

push_swap

sort data on a stack, with a limited set of instructions, using the lowest possible number of actions

Explanation about The algorithm that I use :

algorithm push_swap

To Test

Try to use : ./push_swap -h "this command will show what to do "

Concept of this Project

The idea is simple, You have two stacks called Stack A and Stack B.
Stack A is given a random list of unorganized numbers.
You must take the random list of numbers in Stack A and sort them so that Stack A is organized from smallest to largest.
There are only a few moves you’re allowed to used to manipulate the stacks that we’re going to call “Actions”.
The main goal of this project is to organize Stack A in as few actions as possible.

MOVES

the moves are named: sa, sb, ss, ra, rb, rr, rra, rrb, rrr, pa, pb.
I use Double linked list to implement these moves :

sa || sb 🔃

-swap 2 first element

Screen-Shot-2021-04-03-at-12-44-32-PM

⤴️ ra || rb ↪️

-put the first element last,and all elemnt go UP by one 

Screen-Shot-2021-04-03-at-2-51-42-PM

⤵️ rra || rrb 🔄

-put the last element First, so all elements go DOWN by ine element 

Screen-Shot-2021-04-03-at-5-26-13-PM

pa || pb ➡️

-take the first element at the top of a stack and put it at the top of other_stack.

Screen-Shot-2021-04-03-at-6-41-55-PM Screen-Shot-2021-04-04-at-3-27-57-PM

Checker:

-Thanks to the checker program, you will be able to check if the
list of instructions you’ll generate with the program push_swap is
actually sorting the stack properly.

This is how much instructions the algorithm Do with 100 random number

Screen-Shot-2021-04-11-at-2-46-15-PM

Screen-Shot-2021-04-11-at-2-33-56-PM

About

sort data on a stack, with a limited set of instructions, using the lowest possible number of actions

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published