Skip to content

Edu2metros/push_swap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PUSH SWAP - @42SP

This project is the first project about algorithm in 42 School.

Nota: 84/100 ✔️

What is the Push Swap?

This project is inspired by the Tower of Hanoi, which involves moving a stack of disks from one rod to another, following these rules:

  • Only one disk can be moved at a time.
  • A disk can only be moved if it is the topmost disk.
  • No disk may be placed on top of a smaller disk.

The goal is to transfer the entire stack to another rod, maintaining the original order.

Push Swap involves two stacks, where the first stack is filled with disorganized random numbers. The goal is to organize all the numbers in ascending order using specific movements in the fewest moves possible.

Movements

  • sa (swap a) - Swap the first 2 elements at the top of stack a.

  • sb (swap b) - Swap the first 2 elements at the top of stack b.

  • ss (swap a and b) - sa and sb at the same time.

  • pa (push a) - Take the first element at the top of b and put it at the top of a.

  • pb (push b) - Take the first element at the top of a and put it at the top of b.

  • ra (rotate a) - Shift up all elements of stack a by 1. The first element becomes the last.

  • rb (rotate b) - Shift up all elements of stack b by 1. The first element becomes the last.

  • rr (rotate a and b) - ra and rb at the same time.

  • rra (reverse rotate a) - Shift down all elements of stack a by 1. The last element becomes the first.

  • rrb (reverse rotate b) - Shift down all elements of stack b by 1. The last element becomes the first.

  • rrr (reverse rotate a and b) - rra and rrb at the same time.

How to use

You can compile the program using the command `make test size=(number)´ the program will generate a list of random numbers and sort them using the push_swap program. The program will show the number of movements used to sort the list and the list of movements.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published