This project was made in accordance with the project of School 21 (Ecole 42).
The purpose of this project is to code algorithm for sorting list of integers using two stacks.
push_swap
should sort in ascending order numbers into stack and display a sequence
of instructions that can sort given stack.
You can see the subject here: push_swap.
Main requirements, rules and code style: Norm.
-
At start of the programm there are two stacks named
a
andb
. -
The stack
a
contains a random amount of integers which cannot be duplicated. -
The stack
b
is empty.
Allowed operations with stacks are:
-
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
andsb
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
andrb
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
andrrb
at the same time.
- At evaluation final grade depends on amount of instructions to sort the stack.
-
In this section we should code a
checker
forpush_swap
. -
checker
receives as arguments given stacka
.
It will then wait and read instructions on the standard input. If after executing those instructions, stacka
is actually sorted
andb
is empty, then checker must display "OK\n" on the standard output.
In every other case, checker must display "KO\n" on the standard output.
Makefile compiles given functions into push_swap
or checker
executable file.
Compiler: gcc
Flags: -Wall
-Werror
-Wextra
- Go to the project folder:
$ cd 'path_to_push_swap'
- Then typo one of these command:
Command | Description |
---|---|
make |
compiling mandatory part |
make bonus |
compiling bonus part |
make clean |
clearing all .o files |
make fclean |
clearing all .o files and executables |
- Example of executing
push_swap
:
./push_swap 3 5 2 7 9
- Example of executing
checker
with instructions received frompush_swap
:
ARG="3 5 2 7 9"; ./push_swap $ARG | ./checker $ARG
-
You can check code norm due to norminette.
-
Following checkers should be executed in way like
checker
in this project: