Skip to content
Angela Lima edited this page Apr 10, 2023 · 1 revision

🔄 Welcome to the push_swap wiki!

badge

forthebadge forthebadge

GitHub Language Count GitHub Top Language GitHub Contributors GitHub Last Commit Github License wakatime

🗃️ Introduction

This project will make you sort data on a stack, with a limited set of instructions, using the lowest possible number of actions. To succeed you’ll have to manipulate various types of algorithms and choose the one (of many) most appropriate solution for an optimized data sorting.

The subject states that we have to create at least the push_swap executable and a Makefile.

Project instructions

General

  • The executable file must be named push_swap.
  • You must submit a Makefile. That Makefile needs to compile the project and must contain the usual rules. It can only recompile the program if necessary.
  • Global variables are forbidden.
  • Your project must be written in C in accordance with the Norm.
  • You have to handle errors in a sensitive manner. In no way can your program quit in an unexpected manner (Segmentation fault, bus error, double free, etc).

To solve this problem, we will create push_swap.c, a header and a Makefile, and also a few utils and operations files. Since the subject states that our executable must be named push_swap, in our make all rule, we will compile our files using cc -o <name of executable> <name of c file>:

  • cc -o push_swap push_swap.c will compile the push_swap file and create an executable named push_swap.

The game is composed of 2 stacks named a and b.

  • To start with:
  • the stack a contains a random amount of negative and/or positive numbers which cannot be duplicated.
  • b is empty
  • The goal is to sort in ascending order numbers into stack a.
  • To do this you have the following operations at your disposal:
    • sa : swap a - swap the first 2 elements at the top of stack a. Do nothing if there is only one or no elements).
    • sb : swap b - swap the first 2 elements at the top of stack b. Do nothing if there is only one or no elements).
    • ss : 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. Do nothing if b is empty.
    • pb : push b - take the first element at the top of a and put it at the top of b. Do nothing if a is empty.
    • ra : rotate a - shift up all elements of stack a by 1. The first element becomes the last one.
    • rb : rotate b - shift up all elements of stack b by 1. The first element becomes the last one.
    • rr : 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 one.
    • rrb : reverse rotate b - shift down all elements of stack b by 1. The last element becomes the first one.
    • rrr : rra and rrb at the same time.