How alexhiguera/push_swap works
Project Type and Purpose
• This isn’t a web application or a multi-tier full stack system—instead, it’s an algorithmic challenge with a clear focus on data manipulation using stacks.
• The core goal is to calculate and output a sequence of operations (like push, swap, rotate, and reverse rotate) that sort the provided list of integers.
• It depends on an external personal library (Libft_2.0) for basic functions, so be sure to include external dependency links.
Main Components
a. Main Executable (push_swap):
– The main entry point (src/push_swap.c) that takes the command line arguments and orchestrates the process.
– A node labeled “Input Parsing & Validation” for handling and verifying the input numbers.
b. Stack Manipulation Modules:
– Illustrate two primary logical entities: “Stack A” and “Stack B”. These should be noted as the two main data containers.
• Swap operations (implemented in swap.c)
• Push operations (push.c)
• Rotate and Reverse Rotate operations (rotate.c, reverse_rotate.c)
c. Sorting Algorithm:
– Identify the sorting module (sort.c, moves.c, move_cost.c) that contains the algorithm logic to decide which operations to perform.
– Represent how this module interacts with the stack operations.
d. Helper and Utility Functions:
– Include a module for utilities (utils.c), which likely contains common helper functions.
– Also add “position.c”, “moves.c”, “start.c”, and “stack.c” as parts that maintain and modify the internal state of the stacks.
e. External Dependency:
f. Testing Framework:
– Include a section for testing (from the tests directory). Indicate:
• The tester scripts and executables for both Mac and Linux.
• The “checker” executables (checker_Mac and checker_linux) which are used to verify the correctness of the output.
• Makefile rules (test, exec, normi) as part of the build and verification process.
Relationships and Data Flow
• That the “Main Executable” invokes functions from both the “Sorting Algorithm” and the “Stack Manipulation” modules.
Architectural Patterns and Design Principles
• Single responsibility of each source file: each file (swap, push, rotate, etc.) deals with a specific operation.
• The design shows modularity even within a procedural paradigm by isolating the algorithm logic from low-level operations.
Elements
– Main Executable / Input Handling (push_swap.c)
– Sorting Algorithm (sort.c, moves.c, move_cost.c)
– Stack Operations (swap.c, push.c, rotate.c, reverse_rotate.c)
– Utility Functions (utils.c, position.c, start.c, stack.c)
– Dependencies (Libft_2.0)
– Testing Components (tests/checker_Mac, tests/checker_linux, test scripts)
– The flow of control and data from input through algorithm to the stack modifications.
– The interaction between the Main Executable and Libft.
– The verification loop via the testing scripts.
• Annotations or labels that clarify:
– The role of each module.
– How the stacks (Stack A and Stack B) are managed.
– The limited set of operations as defined by the rules.
Happy diagramming!