PushSwap is a sorting algorithm project that aims to efficiently sort a stack of integers using a predefined set of operations. The project is part of 1337 curriculum and is implemented in C.
To compile the PushSwap program, use the following command:
make
This will generate the executable file push_swap.
Execute the program with a list of integers as command-line arguments:
./push_swap 4 2 8 1 3
This will display the list of operations to sort the stack in ascending order.
PushSwap employs a carefully crafted algorithm designed for optimal sorting efficiency. The algorithm leverages a combination of push and swap operations to achieve a minimal number of steps in sorting the stack. A detailed explanation of the algorithm's logic and efficiency considerations can be found in the source code.
Here are some examples showcasing the usage of PushSwap with different input stacks and their corresponding sorted outputs:
Examples:
./push_swap 4 2 8 1 3
Output:
bash
Operations: sa pb pb sa sa pa pa pa pa
Example 2:
bash
./push_swap 5 2 7 1 4
Output:
bash
Operations: pb pb sa pa sa pa pa