Skip to content

Abla-ouh/Push_swap_42Cursus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

20 Commits
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

LET'S DO SOME SORTING :)

enter image description here

Hi ! This project Iis about sorting data on a stack, with a limited set of instructions, using the lowest possible number of actions. To succeed we have to manipulate various types of algorithms and choose the most appropriate solution (out of many) for an optimized data sorting.

->> FREE TO USE ANY ALGORITHM AS LONG AS IT DO THE REQUIRED <<-

The given instructions ...

instructions Description
sa swap first two elements of stack A
sb swap first two elements of stack B
ss sa and sb at the same time
pa pops the first elememt on B and puts it on top of A
pb pops the first elememt on A and puts it on top of B
ra rotates stuck A up by one
rb rotates stuck B up by one
rr rotates both A and B up by one
rra rotates stuck A down by one
rrb rotates stuck B down by one
rrr rotates both A and B down by one
rrr rotates both A and B down by one

How to compile it ?

For Mandatory part :

--> make

--> ./push_swap [set of random numbers]

ex :

$>./push_swap 2 1 3 6 5 8`
sa
pb
pb
pb
sa
pa
pa
pa
  • You have to write a program named push_swap which will receive as an argument the stack a formatted as a list of integers. The first argument should be at the top of the stack (be careful about the order).
  • The program must display the smallest list of instructions possible to sort the stack a, the smallest number being at the top.
  • Instructions must be separaed by a โ€™\nโ€™ and nothing else.
  • The goal is to sort the stack with the minimum possible number of operations. During defence weโ€™ll compare the number of instructions your program found with a maximum number of operation tolerated. If your program either displays a list too big or if the list isnโ€™t sorted properly, youโ€™ll get no points.
  • In case of error, you must display Error followed by a โ€™\nโ€™ on the standard error. Errors include for example: some arguments arenโ€™t integers, some arguments are bigger than an integer, and/or there are duplicates.

For Bonus part :

--> make bonus

--> ./checker [set of random numbers]

ex :

$>./checker 3 2 1 0
rra
pb
sa
rra
pa
OK
$>./checker 3 2 1 0
sa
rra
pb
KO
$>./checker 3 2 one 0
Error
  • You have to write a program named checker, which will get as an argument the stack a formatted as a list of integers. The first argument should be at the top of the stack (be careful about the order). If no argument is given checker stops and displays nothing.
  • Checker will then wait and read instructions on the standard input, each instruction will be followed by โ€™\nโ€™. Once all the instructions have been read, checker will execute them on the stack received as an argument.
  • If after executing those instructions, stack a is actually sorted and b is empty, then checker must display "OK" followed by a โ€™\nโ€™ on the standard output. In every other case, checker must display "KO" followed by a โ€™\nโ€™ on the standard output.
  • In case of error, you must display Error followed by a โ€™\nโ€™ on the standard error. Errors include for example: some arguments are not integers, some arguments are bigger than an integer, there are duplicates, an instruction donโ€™t exist and/or is incorrectly formatted.

U can find the project's subject here , for more details : Push_swap subject

PS : If you see any error to fix , please dont hesitate to repport it, and u find my project interesting star it. feel free !! *_*

About

Push Swap - ๐Ÿ“š Algorithmic project on C

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published