# dina-elgammal/push_swap_42 architecture

> Architecture diagram of the GitHub repository dina-elgammal/push_swap_42, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dina-elgammal/push_swap_42
- Repository: https://github.com/dina-elgammal/push_swap_42

## Overview

##### Project type and purpose
- This is a command-line “Push_swap” tool written in C.
- Purpose: teach stack data structures and algorithm design by sorting integers using minimal stack operations.

##### File structure
Top-level:
- Push_swap/Makefile – build script
- push_swap.c – main entry point
- pre_checker.c – input validation
- main_sort_utilits.c – orchestration & algorithm selector
- sort_utilits.c, swap.c, push_to_stack.c, rotatedown2top.c, rotatetop2down.c – core stack operations
- helper.c, utilits.c, node_utilits.c – utility functions (array fill, counting, min/max)
- push_swap.h – shared data structures & function signatures

##### README for additional insights
- Describes a two-stack model (`stk_a`, `stk_b`)
- Outlines three entry algorithms: sort_3, sort_5, sort_main_algo (chunk-based)
- Breaks down major helper routines: fill_sort_arr, move_chunk, push_remaining, push_back_chunks

- Labels: clear names for each module and data structure (e.g., “Stack Operations”, “sort_main_algo”)
– Rectangles for code modules
– Parallelograms for I/O (CLI input, operation sequence output)

## Diagram (Mermaid)

```mermaid
graph TB
    CLI["CLI Input"]:::io
    PushSwap["Main Entry Point & Output Module\npush_swap.c"]:::core
    PreChecker["Input & Validation Module\npre_checker.c"]:::validation
    NodeUtils["Core Data Structures\nnode_utilits.c"]:::data
    SortUtils["Array Buffer & Sorting Utilities\nsort_utilits.c"]:::data
    Controller["Controller / Orchestrator\nmain_sort_utilits.c"]:::core
    subgraph "Sorting Algorithms"
        Sort3["sort_3"]:::algo
        Sort5["sort_5"]:::algo
        SortMain["sort_main_algo"]:::algo
    end
    subgraph "Stack Operations"
        PushStack["push_to_stack\n(pb, pa)"]:::ops
        SwapOp["swap\n(sa, sb)"]:::ops
        RotateDown["rotatetop2down\n(ra, rb)"]:::ops
        RotateUp["rotatedown2top\n(rra, rrb)"]:::ops
    end
    subgraph "Helper Utilities"
        HelperMisc["helper.c"]:::util
        Utilits["utilits.c"]:::util
    end
    NodeDef["Shared Definitions & Interfaces\npush_swap.h"]:::defs
    Output["Operation Sequence Output\nstdout"]:::io
    subgraph "Project Resources"
        Makefile["Makefile"]:::docs
        README["README.md"]:::docs
    end

    CLI --> PushSwap
    PushSwap --> PreChecker
    PreChecker --> NodeUtils
    NodeUtils --> SortUtils
    SortUtils --> Controller
    Controller --> Sort3
    Controller --> Sort5
    Controller --> SortMain
    Sort3 --> PushStack
    Sort3 --> SwapOp
    Sort3 --> RotateDown
    Sort3 --> RotateUp
    Sort5 --> PushStack
    Sort5 --> SwapOp
    Sort5 --> RotateDown
    Sort5 --> RotateUp
    SortMain --> SortUtils
    SortMain --> HelperMisc
    SortMain --> PushStack
    SortMain --> SwapOp
    SortMain --> RotateDown
    SortMain --> RotateUp
    PushStack --> Output
    SwapOp --> Output
    RotateDown --> Output
    RotateUp --> Output
    HelperMisc --> PushStack
    HelperMisc --> SwapOp
    HelperMisc --> RotateDown
    HelperMisc --> RotateUp
    Utilits --> PushStack
    Utilits --> SwapOp
    Utilits --> RotateDown
    Utilits --> RotateUp
    NodeDef --> PreChecker
    NodeDef --> PushSwap
    NodeDef --> Controller
    NodeDef --> NodeUtils
    NodeDef --> SortUtils
    NodeDef --> PushStack
    NodeDef --> SwapOp
    NodeDef --> RotateDown
    NodeDef --> RotateUp
    NodeDef --> HelperMisc
    NodeDef --> Utilits

    classDef io fill:#FFA500,stroke:#333,stroke-width:1px;
    classDef validation fill:#ADD8E6,stroke:#333,stroke-width:1px;
    classDef core fill:#4169E1,stroke:#333,stroke-width:1px,color:#fff;
    classDef data fill:#9370DB,stroke:#333,stroke-width:1px,color:#fff;
    classDef algo fill:#32CD32,stroke:#333,stroke-width:1px;
    classDef ops fill:#FF69B4,stroke:#333,stroke-width:1px;
    classDef util fill:#FFFF66,stroke:#333,stroke-width:1px;
    classDef defs fill:#A9A9A9,stroke:#333,stroke-width:1px;
    classDef docs fill:#D3D3D3,stroke:#333,stroke-width:1px;

    click PreChecker "https://github.com/dina-elgammal/push_swap_42/blob/main/Push_swap/pre_checker.c"
    click PushSwap "https://github.com/dina-elgammal/push_swap_42/blob/main/Push_swap/push_swap.c"
    click Controller "https://github.com/dina-elgammal/push_swap_42/blob/main/Push_swap/main_sort_utilits.c"
    click NodeUtils "https://github.com/dina-elgammal/push_swap_42/blob/main/Push_swap/node_utilits.c"
    click SortUtils "https://github.com/dina-elgammal/push_swap_42/blob/main/Push_swap/sort_utilits.c"
    click PushStack "https://github.com/dina-elgammal/push_swap_42/blob/main/Push_swap/push_to_stack.c"
    click SwapOp "https://github.com/dina-elgammal/push_swap_42/blob/main/Push_swap/swap.c"
    click RotateDown "https://github.com/dina-elgammal/push_swap_42/blob/main/Push_swap/rotatetop2down.c"
    click RotateUp "https://github.com/dina-elgammal/push_swap_42/blob/main/Push_swap/rotatedown2top.c"
    click HelperMisc "https://github.com/dina-elgammal/push_swap_42/blob/main/Push_swap/helper.c"
    click Utilits "https://github.com/dina-elgammal/push_swap_42/blob/main/Push_swap/utilits.c"
    click NodeDef "https://github.com/dina-elgammal/push_swap_42/blob/main/Push_swap/push_swap.h"
    click Makefile "https://github.com/dina-elgammal/push_swap_42/tree/main/Push_swap/Makefile"
    click README "https://github.com/dina-elgammal/push_swap_42/blob/main/README.md"
```
