Push_swap is a project from École 42 that challenges students to sort a list of integers using two stacks and a limited set of operations. The objective is to sort the data with the fewest possible moves, demonstrating proficiency in algorithm optimization and data structure manipulation.
The project involves creating a program that generates a sequence of operations to sort a stack of integers. Additionally, a checker program verifies the correctness of the sorting operations. The allowed operations include swapping, pushing, and rotating elements between two stacks, a and b.
-
Sorting Algorithm:
- Develops an efficient algorithm to sort integers using two stacks and a predefined set of operations.
-
Checker Program:
- Validates the sequence of operations to ensure the stack is sorted correctly.
-
Operations:
sa(swap a): Swap the first two elements at the top of stacka.sb(swap b): Swap the first two elements at the top of stackb.ss: Performsaandsbsimultaneously.pa(push a): Move the top element from stackbto stacka.pb(push b): Move the top element from stackato stackb.ra(rotate a): Shift all elements of stackaup by one.rb(rotate b): Shift all elements of stackbup by one.rr: Performraandrbsimultaneously.rra(reverse rotate a): Shift all elements of stackadown by one.rrb(reverse rotate b): Shift all elements of stackbdown by one.rrr: Performrraandrrbsimultaneously.
-
Input Parsing:
- The program accepts a list of integers as arguments, representing the initial stack
a.
- The program accepts a list of integers as arguments, representing the initial stack
-
Algorithm Execution:
- Utilizes sorting algorithms to determine the optimal sequence of operations to sort stack
a.
- Utilizes sorting algorithms to determine the optimal sequence of operations to sort stack
-
Operation Output:
- Outputs the sequence of operations required to sort the stack.
-
Validation:
- The checker program reads the initial stack and the sequence of operations, then verifies if the stack is sorted correctly.