Push_swap is a project designed to test algorithmic thinking, problem-solving, and optimization skills. The goal is to sort a stack of integers using a limited set of operations, while achieving the most efficient solution in terms of the number of moves. The project consists of two main programs:
This program generates a sequence of commands to sort a list of integers. The available operations include pushing elements between two stacks (push), rotating stacks (rotate), reversing stack rotations (reverse rotate), and swapping the first two elements of a stack (swap). The challenge is to use these operations optimally. The program required the implementation of a cost dependant algorithm to define the most efficient way to sort elements in a stack.
This is a separate program that takes the list of commands outputted by push_swap and the initial list of integers to verify if the result is sorted correctly.
Push_swap emphasizes the importance of writing efficient, clean, and well-structured code. It also serves as an introduction to algorithmic optimization.
-
Clone repository
git clone git@github.com:mjorgecruz/42_push_swap.git
-
Run
make
cd 42_push_swap make
-
Run
./push_swap {list_of_numbers}
./push_swap 1 3 2 5 4