PushSwap stands as one of my significant achievements. This project revolves around efficiently sorting data using a restricted number of operations, adding complexity to the task. Instead of relying on existing algorithms, I collaborated with peers to devise an innovative solution. Our approach proved to be lightning-fast and remarkably effective, successfully sorting the data with the minimal required operations.
To use the mandatory part of PushSwap, follow these steps:
- Run the
make
command to compile the program. - Execute the binary with some numbers as arguments. For example:
$ ./push_swap 1 2 3 4 5
To use the bonus part of PushSwap, follow these steps:
- Run the
make bonus
command to compile the program. - Execute the binary with some numbers as arguments. For example:
$ ./checker 1 2 3 4 5
-
Index the numbers on stack A by their order in the list. Assign an index to each number in the list, starting from 0 for the smallest number and incrementing by 1 for each larger number. For instance, in the list [7, 2, 0], 7 would have the highest index, followed by 2 and then 0.
-
Determine the appropriate range based on the size of stack A. The range defines the numbers that will be pushed onto stack B during each iteration. If the size of stack A is less than or equal to 250, use a range of [0, 15]. For larger stacks (size greater than 250), use a range of [0, 35].
-
Push numbers within the range onto stack B. Iterate through the numbers in stack A and push those that fall within the current range onto stack B.
-
With each push operation, increment the range by 1. This ensures that a wider range of numbers is considered during subsequent iterations.
-
Return numbers from stack B to stack A in reverse order. After emptying stack A, start returning numbers from stack B to stack A. Begin with the number that has the highest index in stack B and continue returning numbers in decreasing order of their indices.
By following these steps, you can effectively implement the algorithm.
- GitHub: Ziko909
- LinkedIn: Zakaria Aabou
- Gmail: aabou.zakaria909@gmail.com