Skip to content

This project had me sort data into a stack, with a limited set of instructions, using as few shares as possible. To succeed, I had to manipulate several types of algorithms and choose the most appropriate solution (out of many) for a optimized data classification.

Notifications You must be signed in to change notification settings

LuMedeir/Push_Swap_42

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Push Swap


Description

Given a set of integers, sort it using a predefined set of instructions using two stacks. The instruction set is defined below. This program outputs a program in push_swap instructions that sorts the input integers.

Rules

For the following instructions, if the instruction is not possible, the part of it that can't be executed won't.

Code Instruction Action
sa swap a swaps the 2 top elements of stack a
sb swap b swaps the 2 top elements of stack b
ss swap a + swap b both sa and sb
pa push a moves the top element of stack b at the top of stack a
pb push b moves the top element of stack a at the top of stack b
ra rotate a shifts all elements of stack a from bottom to top
rb rotate b shifts all elements of stack b from bottom to top
rr rotate a + rotate b both ra and rb
rra reverse rotate a shifts all elements of stack a from top to bottom
rrb reverse rotate b shifts all elements of stack b from top to bottom
rrr reverse rotate a + reverse rotate b both rra and rrb

You can run it with:

  $> ./push_swap <list_of_numbers>

Makefile rules

Rule Description
make Compile the program.
make clean Remove every objects of compilation
make fclean Do clean rule and remove the executable program
make re Do fclean rule and compile the program mandatory

About

This project had me sort data into a stack, with a limited set of instructions, using as few shares as possible. To succeed, I had to manipulate several types of algorithms and choose the most appropriate solution (out of many) for a optimized data classification.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published