How rodcabral/sort works
Main components
• Main Application: Represented by main.c. This is the entry point and control hub of the program.
• Sorting Module: Implemented in sort.h and src/sort.c. This module contains all the logic for implementing the different sorting algorithms (Merge Sort, Bubble Sort, Selection Sort, and Insertion Sort).
• Visualization Module: Provided by visualizer.h and src/visualizer.c. This module interacts with the SDL2 libraries to render the visualization of the sorting process.
• Assets & Resources: Represented by the assets folder (and fonts folder for font files). These contain images (e.g., the example.png) and other resources needed for the visualization.
• External Dependencies: SDL2 and SDL2_ttf libraries, which are critical for rendering and handling text.
Relationships and interactions
• The Main Application initializes the program, sets up the necessary SDL2 components, and orchestrates the flow.
• The Sorting Module encapsulates the logic of the algorithms. The main application calls functions in this module to perform sorting while generating intermediate states or steps.
• The Visualization Module relies on SDL2 for creating windows, rendering text, and displaying graphics. It takes the states provided by the sorting module and visualizes them on the screen.
• The assets (images and fonts) serve as auxiliary resources that the visualizer loads and displays.
• The Makefile and build scripts facilitate compiling the source code and linking with the necessary libraries.
Architectural patterns/design principles
• Modularity: The separation between sorting and visualization code encourages a modular structure – each module is focused on a specific responsibility.
• Layering: Think of it as a two-layered approach, where the lower layer contains the sorting computations and the upper layer deals with presentation and user interaction.
• Dependency inversion: The main module coordinates between the independent sorting and visualization modules.
• Abstraction: The use of header (.h) and source files helps encapsulate the functionalities for sorting and visualization, making the code easier to maintain and extend.
• Main Application to the Sorting Module (to trigger and retrieve sorting data).
• Main Application to the Visualization Module (to display the sorting process).
• External Dependencies (SDL2 and SDL2_ttf) in a separate area. Connect these dependencies with a line to the Visualization Module to denote external library usage.