Skip to content

"push_swap" is a 42 curriculum project that challenges students to sort a stack of integers using limited instructions. It requires creative algorithm design and efficient use of stack operations.

Notifications You must be signed in to change notification settings

Elhazin/push_swap

Repository files navigation

push_swap

Push Swap is a project in the 42 curriculum with the objective of sorting a stack. Due to the structure of the stack, you will need to solve it using specific instructions.


What are the instructions?

  • pa and pb: To sort the stack, you will have a little help in the form of a temporary stack that will be used to store some data to return it back when you finish sorting.

    • pa: This is used when you want to push some element onto stack A.
    • pb: This is used when you want to push some element onto stack B.
  • sa and sb: These instructions are used to swap the first (the top) element with the second element in the stack.

Screenshot

  • ra and rb: These instructions will rotate the elements, with the first (the top) element becoming the last element in the stack (at the bottom), and the second element becoming the top element in the stack.

Screenshot

  • rra and rrb: These instructions are used to take the last element in the stack and move it to the first position in the stack. The first (the top) element in the stack will become the second element.

How to work now?

You will need to find an algorithm that uses as few instructions as possible. First, you have to understand how the stack works and implement a stack data structure because in C, there is no built-in data structure called "stack."

About

"push_swap" is a 42 curriculum project that challenges students to sort a stack of integers using limited instructions. It requires creative algorithm design and efficient use of stack operations.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published