An efficient stack-sorting algorithm powered by Turk Sort
- Only the following external functions are allowed: read, write, malloc, free, exit
- On error, the program must print Error followed by a newline and exit with a non-zero status
- All inputs are validated before processing to avoid undefined behavior. No duplicates or non numeric input.
- GCC or Clang
- Make
Use make in your terminal to build and manage the project:
makeCommon targets:
make— buildspush_swapmake clean— removes object filesmake fclean— removes objects and binariesmake re— full rebuild
You can pass numbers either as separate arguments or as a single-quoted string:
./push_swap 2 1 3 6 5 8
./push_swap "2 1 3 6 5 8"The program prints the sequence of operations to stdout, one per line, for the checker to validate and score.
Invalid input examples (program prints Error and exits with a non-zero status):
- Non-numeric token:
./push_swap 2 a 3 - Duplicate:
./push_swap 1 2 2 - Out of 32-bit int range:
./push_swap 2147483648
Manual quick checks:
./push_swap 2 1
./push_swap 3 2 1
./push_swap 2 3 1 5 4
./push_swap "-3 0 42 7 -1 5 5" # duplicate -> Error
./push_swap 2147483648 # overflow -> ErrorOptionally measure move counts:
ARG=$(seq 1 100 | shuf | tr '\n' ' '); OPS=$(./push_swap $ARG | wc -l); echo $OPSinclude/
list.h # t_list struct and typedef
ops_base.h # low-level stack ops API
push_swap.h # public API, parsing, sorting
src/
ops/ # op_* and ops_base/execute
parser/ # input parsing and utils
sort/ # cost calc, helpers, main sort
stack/ # list utils, search, push/pop
libft/ # local lib (printf, utils, etc.)
Makefile # build rules
