push_swap is a 42 project that challenges students to create an efficient sorting algorithm to sort a stack of numbers with a limited set of operations. The aim is to sort the stack using the least number of moves possible. This project implements the "Turk algorithm," a strategic approach to solving the problem as discussed in this article. The algorithm works by calculating which move will take the least amount of moves to get the lists closer to being sorted.
- Sort a stack of integers using two stacks and a limited set of operations.
- Check for errors and handle non-integer and duplicate inputs.
- Print the list of operations needed to sort the stack.
The bonus part of push_swap introduces additional features:
- Checker Program: A separate program that checks if the stack is sorted after applying the operations given by
push_swap.
To clone the repository use:
git clone https://github.com/moop250/push_swap.gitCompilation & cleanup:
make: Compiles the push_swap program.make bonus: Compiles the checker program.make all: Compiles both the push_swap and checker programs.make clean: Cleans up object files (.o).make fclean: Cleans up all files generated by running make, including executables.make re: Performs a make fclean followed by a make all to recompile the programs.
Example usage of push_swap:
ARG="4 67 3 87 23"; ./push_swap $ARGExample usage with checker bonus:
ARG="4 67 3 87 23"; ./push_swap $ARG | ./checker $ARG