Project 7: Push Swap - Seventh project for the formation of software engineers at school 42 São Paulo.
- This project aim to sort data on a stack, with a limited set of instructions, using the lowest possible number of operations.
Operation | Description |
---|---|
sa (swap a) | Swap the first 2 elements at the top of stack a |
sb (swap b) | Swap the first 2 elements at the top of stack b |
pa (push a) | Take the first element at the top of b and put it at the top of a |
pb (push b) | Take the first element at the top of a and put it at the top of b |
ra (rotate a) | Shift up all elements of stack a by 1 |
rb (rotate b) | Shift up all elements of stack b by 1 |
rr | ra and rb at the same time |
rra (reverse rotate a) | Unsigned hexadecimal integer (uppercase) |
rrb (reverse rotate b) | Shift down all elements of stack b by 1 |
rrr | rra and rrb at the same time. |
To test, you should run the Make all command
make all
Now compile the executable file generated by the makefile and add the parameters you want. For example:
./push_swap 42 142 9123 -123 -254231278 -10470 12748 -15027 -17306 1864
We can check stacks A and B. On the right, we can see the operation that was used.
Example 1) Sorting with 5 random and distinct integers:
Example 2) Sorting with 100 random and distinct integers:
42.sp.mp4
Example 3) Sorting with 1000 random and distinct integers: