The Push_swap project challenged me to implement a sorting algorithm using a set of predefined operations on two stacks. The goal was to sort data with the fewest possible actions, optimizing both for performance and efficiency.
The task was to create a program named push_swap
that sorts a list of integers provided as arguments using a limited set of operations. This project introduced me to sorting algorithms, data structures, and the concept of algorithmic complexity—key topics for any software developer.
- Stack Operations: Manipulated data using a range of operations like
sa
(swap),ra
(rotate), andpb
(push). - Algorithmic Optimization: Focused on minimizing the number of moves to sort a stack in ascending order.
- Error Handling: Managed input validation, ensuring all arguments are valid integers, without duplicates or exceeding integer limits.
sa
– Swap the first two elements of stacka
.sb
– Swap the first two elements of stackb
.ss
– Performsa
andsb
simultaneously.pa
– Push the top element of stackb
onto stacka
.pb
– Push the top element of stacka
onto stackb
.ra
– Rotate stacka
(move the first element to the bottom).rb
– Rotate stackb
.rr
– Performra
andrb
simultaneously.rra
– Reverse rotate stacka
(move the last element to the top).rrb
– Reverse rotate stackb
.rrr
– Performrra
andrrb
simultaneously.
- Algorithm Optimization: Understood the importance of minimizing complexity and choosing the best algorithmic approach for each scenario.
- Sorting Algorithms: Implemented and adapted sorting techniques to efficiently handle stacks.
- C Programming: Improved my skills in memory management and error handling, ensuring no leaks and handling various edge cases.
make
./push_swap <list of numbers>
(without duplicate)
To use the visualiser like in the gif below : https://gitlab.com/nda-cunh/visualizer-push-swap