This is a C program for sorting a stack of numbers using a specific set of operations. The program implements various sorting algorithms based on the size of the input list. It includes functions for operations like pushing, popping, rotating, and swapping elements in the stacks.
- Introduction
- Algorithms
- Utility Functions
- Main Function
- Input Validation
- Error Handling
- Print Functions
- Memory Management
- Compilation and Execution
The program is designed to sort a stack of numbers using a set of specific operations. It includes the following main components:
-
algorithm
: This function determines which sorting algorithm to use based on the size of the stack. -
sort_three_nums
: Sorts three numbers in the stack. -
sort_five_nums
: Sorts five numbers in the stack. -
sort_ten_num
: Sorts ten numbers in the stack. -
sort_mult_nums
: Sorts a stack with more than ten numbers.
-
quick_sort
: Implements a quick sort algorithm for sorting arrays. -
Various stack manipulation functions like
push
,pop
,rotate
,swap
, etc.
main
: Reads input numbers, initializes stacks, calls the sorting algorithm, and prints the result.
ft_atoi
: Converts a string to an integer, handling whitespace and error cases.
ft_error
: Prints an error message and exits the program.
print_list
: Prints the elements of a linked list.
deallocate
: Frees memory allocated for a linked list.
To compile and run the program, use the following commands:
make
./push_swap <list_of_numbers>
Replace <list_of_numbers>
with the numbers you want to sort, separated by spaces.
Note: This program assumes that the input is valid and contains only integer values.
Feel free to modify, improve, and extend this code as needed for your specific use case. Happy coding!