# fuzzycactus42/push_swap architecture

> Architecture diagram of the GitHub repository fuzzycactus42/push_swap, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/fuzzycactus42/push_swap
- Repository: https://github.com/fuzzycactus42/push_swap

## Overview

push_swap is a command-line integer sorter: it parses and validates input, builds stack A, chooses a sorting strategy, and prints stack-operation instructions that leave A sorted and B empty. Adaptive selection uses disorder; users can also select Simple, Medium, or Complex, and optionally request benchmark statistics. The small-input Simple override is applied during input preparation. Relationships among the unsampled dispatcher, ranking, disorder, and benchmark implementations follow README descriptions; their source bodies were not provided.

Main entry points: [`main.c`](https://github.com/fuzzycactus42/push_swap/blob/main/main.c) (Program entry), [`push_swap.c`](https://github.com/fuzzycactus42/push_swap/blob/main/push_swap.c) (Strategy dispatch), [`Operations`](https://github.com/fuzzycactus42/push_swap/tree/main/Operations) (Stack operations), [`str2int.c`](https://github.com/fuzzycactus42/push_swap/blob/main/str2int.c) (Token conversion)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_input["Input and validation"]
  node_main["Program entry<br/>[main.c]"]
  node_flags["Flag parsing<br/>[read_flags.c]"]
  node_tokens["Token conversion<br/>[str2int.c]"]
  node_split["Argument splitting<br/>[ft_split.c]"]
  node_integer["Integer parsing<br/>[ft_atoi.c]"]
  node_duplicates["Duplicate checks<br/>[check_dup_error.c]"]
end

subgraph group_control["Strategy and reporting"]
  node_dispatcher["Strategy dispatch<br/>[push_swap.c]"]
  node_disorder["Disorder measure<br/>[get_disorder.c]"]
  node_benchmark["Benchmark statistics<br/>[bench.c]"]
  node_output["Printed instructions"]
  node_bench_output["Benchmark report"]
end

subgraph group_algorithms["Sorting strategies"]
  node_ranking["Rank values<br/>[ranking.c]"]
  node_simple["Simple extraction<br/>[simple.c]"]
  node_medium["Medium chunks<br/>[medium.c]"]
  node_complex["Complex radix<br/>[complex.c]"]
end

subgraph group_stacks["Stacks and operations"]
  node_stack["Stack storage<br/>[stack_utils.c]"]
  node_operations["Stack operations"]
end

node_user(("CLI user"))

node_user -->|"provides arguments"| node_main
node_main -->|"parses options"| node_flags
node_main -->|"converts values"| node_tokens
node_tokens -->|"splits arguments"| node_split
node_tokens -->|"parses tokens"| node_integer
node_main -->|"checks uniqueness"| node_duplicates
node_main -->|"fills stack"| node_stack
node_main -->|"starts sorting"| node_dispatcher
node_dispatcher -->|"measures disorder"| node_disorder
node_dispatcher -->|"selects strategy"| node_simple
node_dispatcher -->|"selects strategy"| node_medium
node_dispatcher -->|"selects strategy"| node_complex
node_medium -->|"ranks values"| node_ranking
node_complex -->|"ranks values"| node_ranking
node_simple -->|"issues operations"| node_operations
node_medium -->|"issues operations"| node_operations
node_complex -->|"issues operations"| node_operations
node_operations -->|"prints instructions"| node_output
node_dispatcher -->|"reports counts"| node_benchmark
node_benchmark -->|"writes statistics"| node_bench_output

click node_main "https://github.com/fuzzycactus42/push_swap/blob/main/main.c"
click node_flags "https://github.com/fuzzycactus42/push_swap/blob/main/read_flags.c"
click node_tokens "https://github.com/fuzzycactus42/push_swap/blob/main/str2int.c"
click node_split "https://github.com/fuzzycactus42/push_swap/blob/main/ft_split.c"
click node_integer "https://github.com/fuzzycactus42/push_swap/blob/main/ft_atoi.c"
click node_duplicates "https://github.com/fuzzycactus42/push_swap/blob/main/check_dup_error.c"
click node_stack "https://github.com/fuzzycactus42/push_swap/blob/main/stack_utils.c"
click node_dispatcher "https://github.com/fuzzycactus42/push_swap/blob/main/push_swap.c"
click node_disorder "https://github.com/fuzzycactus42/push_swap/blob/main/get_disorder.c"
click node_ranking "https://github.com/fuzzycactus42/push_swap/blob/main/ranking.c"
click node_simple "https://github.com/fuzzycactus42/push_swap/blob/main/Algorithms/simple.c"
click node_medium "https://github.com/fuzzycactus42/push_swap/blob/main/Algorithms/medium.c"
click node_complex "https://github.com/fuzzycactus42/push_swap/blob/main/Algorithms/complex.c"
click node_operations "https://github.com/fuzzycactus42/push_swap/tree/main/Operations"
click node_benchmark "https://github.com/fuzzycactus42/push_swap/blob/main/bench.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_flags,node_tokens,node_split,node_integer,node_duplicates,node_user toneBlue
class node_dispatcher,node_disorder,node_benchmark,node_output,node_bench_output toneAmber
class node_ranking,node_simple,node_medium,node_complex toneMint
class node_stack,node_operations toneRose
```

## Components

### Input and validation

- [Program entry](https://github.com/fuzzycactus42/push_swap/blob/main/main.c): `main.c`
- [Flag parsing](https://github.com/fuzzycactus42/push_swap/blob/main/read_flags.c): `read_flags.c`
- [Token conversion](https://github.com/fuzzycactus42/push_swap/blob/main/str2int.c): `str2int.c`
- [Argument splitting](https://github.com/fuzzycactus42/push_swap/blob/main/ft_split.c): `ft_split.c`
- [Integer parsing](https://github.com/fuzzycactus42/push_swap/blob/main/ft_atoi.c): `ft_atoi.c`
- [Duplicate checks](https://github.com/fuzzycactus42/push_swap/blob/main/check_dup_error.c): `check_dup_error.c`

### Strategy and reporting

- [Strategy dispatch](https://github.com/fuzzycactus42/push_swap/blob/main/push_swap.c): `push_swap.c`
- [Disorder measure](https://github.com/fuzzycactus42/push_swap/blob/main/get_disorder.c): `get_disorder.c`
- [Benchmark statistics](https://github.com/fuzzycactus42/push_swap/blob/main/bench.c): `bench.c`
- **Printed instructions**
- **Benchmark report**

### Sorting strategies

- [Rank values](https://github.com/fuzzycactus42/push_swap/blob/main/ranking.c): `ranking.c`
- [Simple extraction](https://github.com/fuzzycactus42/push_swap/blob/main/Algorithms/simple.c): `Algorithms/simple.c`
- [Medium chunks](https://github.com/fuzzycactus42/push_swap/blob/main/Algorithms/medium.c): `Algorithms/medium.c`
- [Complex radix](https://github.com/fuzzycactus42/push_swap/blob/main/Algorithms/complex.c): `Algorithms/complex.c`

### Stacks and operations

- [Stack storage](https://github.com/fuzzycactus42/push_swap/blob/main/stack_utils.c): `stack_utils.c`
- [Stack operations](https://github.com/fuzzycactus42/push_swap/tree/main/Operations): `Operations`

### Other components

- **CLI user**

## Connections

- CLI user → Program entry: provides arguments (evidence: `README.md`)
- Program entry → Flag parsing: parses options (evidence: `main.c`)
- Program entry → Token conversion: converts values (evidence: `main.c`)
- Token conversion → Argument splitting: splits arguments (evidence: `str2int.c`)
- Token conversion → Integer parsing: parses tokens (evidence: `str2int.c`)
- Program entry → Duplicate checks: checks uniqueness (evidence: `main.c`)
- Program entry → Stack storage: fills stack (evidence: `main.c`)
- Program entry → Strategy dispatch: starts sorting (evidence: `README.md`)
- Strategy dispatch → Disorder measure: measures disorder (evidence: `README.md`)
- Strategy dispatch → Simple extraction: selects strategy (evidence: `README.md`)
- Strategy dispatch → Medium chunks: selects strategy (evidence: `README.md`)
- Strategy dispatch → Complex radix: selects strategy (evidence: `README.md`)
- Medium chunks → Rank values: ranks values (evidence: `Algorithms/medium.c`)
- Complex radix → Rank values: ranks values (evidence: `Algorithms/complex.c`)
- Simple extraction → Stack operations: issues operations (evidence: `Algorithms/simple.c`)
- Medium chunks → Stack operations: issues operations (evidence: `Algorithms/medium.c`)
- Complex radix → Stack operations: issues operations (evidence: `Algorithms/complex.c`)
- Stack operations → Printed instructions: prints instructions (evidence: `Operations/push.c`)
- Strategy dispatch → Benchmark statistics: reports counts (evidence: `README.md`)
- Benchmark statistics → Benchmark report: writes statistics (evidence: `README.md`)
