Command-Line Syntax
The Push Swap program accepts integers as command-line arguments and outputs the sequence of operations needed to sort them.Basic Invocation
Input Formats
Push Swap supports two different input formats, handled inmain.c:15-35:
Multiple Arguments Format
When you pass numbers as separate arguments, each number is a distinct command-line parameter:argv + 1 directly to ft_fill_stack() with flag 0 (main.c:31).
Single String Format
When you pass numbers as a single quoted string, the program splits it internally:ft_split() to parse the string by spaces (main.c:26), then processes the result with flag 1 to ensure proper memory cleanup.
Understanding the Output
The program outputs a sequence of operations, one per line:Output
- sa, sb, ss: Swap operations
- pa, pb: Push operations
- ra, rb, rr: Rotate operations
- rra, rrb, rrr: Reverse rotate operations
Output Interpretation
The output sequence represents the steps to sort the input numbers in ascending order:- All numbers start in stack A
- Stack B starts empty
- Apply each operation in order
- Final result: sorted numbers in stack A, stack B empty
Example Walkthrough
For input3 2 1:
Edge Cases
The program handles several edge cases automatically:Empty or No Input
argc == 1 or when given an empty string.
Already Sorted Input
is_stack_sorted() check in push_swap.c:85 detects pre-sorted input and skips sorting.
Two Numbers
Output
Next Steps
- See Usage Examples for more complex sorting scenarios
- Learn about Error Handling for invalid inputs
- Explore the Operations Reference to understand each operation