/42_codam_push_swap

The Push_swap project is a very simple and highly effective algorithm project: data will need to be sorted. You have at your disposal a set of int values, 2 stacks and a set of instructions to manipulate both stacks.

Primary LanguageC

42_codam_push_swap

The Push_swap project is a very simple and highly effective algorithm project: data will need to be sorted. You have at your disposal a set of int values, 2 stacks and a set of instructions to manipulate both stacks.

Usage

The push_swap program will be executed as follows:

./push_swap <list_of_integers>

It takes 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).

Goal

The goal is to sort the stack with the lowest possible number of operations.

Constraints

Functions allowed: read, write, malloc, free, exit.

Return value

  • 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 separated by a ’\n’ and nothing else.
  • If no parameters are specified, the program must not display anything and give the prompt back.
  • In case of error, it 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.

Flowchart

Overview

image

Input parsing

image

Indexing

image

Applying the sort algorithm

image

Radix sort

image

checker_bonus

Thanks to the checker program, you will be able to check whether the list of instructions generated by the push_swap program actually sorts the stack properly.

Usage

The checker program will be executed as follows:

./checker <list_of_integers>