Table of Contents
This project involves sorting data on a stack, with a limited set of instructions, and the smallest number of moves. To make this happen, you will have to manipulate various sorting algorithms and choose the most appropriate solution(s) for optimized data sorting.
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.
Program name | push_swap |
Makefile | all , clean , fclean , re |
Arguments | a random list of integers |
External functs. | write , read , malloc , free , exit |
Libft authorized | Yes |
./
├── includes/ # header files
├── libft/ # library files
├── src/ # source files
└── Makefile
- MacOS 12.1(Monterey, Intel)
Developed and tested in this environment.
$ git clone https://github.com/srngch/42push_swap
$ make
Run compiled executable file in the root folder.
$ ./push_swap [numbers]
# print instructions
$ ./push_swap 1 3 2 5 4
pb
ra
pb
sa
rra
pa
pa
# print nothing if the list is already sorted
$ ./push_swap 1 2 3 4 5
# print nothing if argument is not provided
$ ./push_swap
# print error if argument is not a integer
$ ./push_swap 0 one 2 3
Error
# print error if argument is not a range of integers
$ ./push_swap 2147483648
Error
# print error if argument is duplicated
$ ./push_swap 1 2 3 1
Error
# check if the list is sorted
$ ARG="1 5 2 4 3"; ./push_swap $ARG | ./checker_Mac $ARG
OK