The push_swap
project is designed to test and improve your algorithmic skills by sorting data using stacks. You will implement a program that sorts a stack of integers using a defined set of operations. The goal is to achieve this with the minimum number of operations.
The push_swap
program must sort a list of integers passed as arguments using two stacks named a
and b
. Initially, stack a
contains the integers, and stack b
is empty. The program must produce the shortest sequence of operations to sort the integers in ascending order in stack a
.
The allowed operations are:
sa
: Swap the first two elements at the top of stacka
.sb
: Swap the first two elements at the top of stackb
.ss
:sa
andsb
simultaneously.pa
: Push the top element of stackb
onto stacka
.pb
: Push the top element of stacka
onto stackb
.ra
: Rotate stacka
upwards (top element becomes the last).rb
: Rotate stackb
upwards (top element becomes the last).rr
:ra
andrb
simultaneously.rra
: Reverse rotate stacka
(bottom element becomes the first).rrb
: Reverse rotate stackb
(bottom element becomes the first).rrr
:rra
andrrb
simultaneously.
The push_swap
program consists of several key components:
error_check.c
: Validates the input arguments to ensure they are integers and there are no duplicates.pile_operations.c
: Contains the implementation of stack operations such as push, swap, rotate, and reverse rotate.pile_memory_management.c
: Manages the memory allocation and deallocation for the stacks.pile_interchanger.c
: Manages the transfer of elements between stacksa
andb
.sort_pile.c
: Implements the sorting algorithm to determine the sequence of operations needed to sort the stack.tiny_sort.c
: Provides optimized sorting methods for small sets of integers.sort_group.c
andsort_rotation.c
: Implement advanced sorting strategies and rotations to minimize the number of operations.push_swap_main.c
: The main entry point of the program, which initializes the stacks, processes input, and invokes the sorting algorithm.