# alamtafe/push_swap architecture

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

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

## Overview

This is a push_swap program: it parses integer arguments into a stack, assigns sortable indices, then emits stack-operation instructions intended to sort the values. The visible entry point calls parsing, indexing, and a selection-sort entry; the repository also contains simple, chunk-based, radix, and adaptive sorting modules plus stack-operation implementations. The README is empty, and several sorting implementations are unsampled, so their internal dispatch and helper relationships are not asserted.

Main entry points: [`main.c`](https://github.com/alamtafe/push_swap/blob/main/main.c) (Program Entry), [`parsing/parsing.c`](https://github.com/alamtafe/push_swap/blob/main/parsing/parsing.c) (Argument Parsing), [`sorting`](https://github.com/alamtafe/push_swap/tree/main/sorting) (Sort Selection), [`operations/push.c`](https://github.com/alamtafe/push_swap/blob/main/operations/push.c) (Push Operations)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_input["Input and Setup"]
  node_main["Program Entry<br/>[main.c]"]
  node_parsing["Argument Parsing<br/>[parsing.c]"]
end

subgraph group_sorting["Sorting Strategies"]
  node_selector["Sort Selection"]
  node_adaptive["Adaptive Strategy<br/>[adaptive.c]"]
  node_simple["Small Sort<br/>[simple.c]"]
  node_chunk["Chunk Sort<br/>[medium.c]"]
  node_radix["Radix Sort<br/>[complex.c]"]
end

subgraph group_operations["Stack Operations"]
  node_push_ops["Push Operations<br/>[push.c]"]
  node_rotate_ops["Rotate Operations<br/>[rotate.c]"]
  node_reverse_ops["Reverse Rotations<br/>[reverse_rotate.c]"]
  node_swap_ops["Swap Operations<br/>[swap.c]"]
end

subgraph group_helpers["Runtime Helpers"]
  node_tokens["Token Utilities<br/>[ft_split.c]"]
  node_numeric["Number Conversion<br/>[ft_atol.c]"]
  node_stack_build["Stack Construction<br/>[new_list.c]"]
  node_stack_cleanup["Memory Cleanup<br/>[free_list.c]"]
  node_indexing["Index Assignment<br/>[set_index.c]"]
  node_chunk_helper["Chunk Selection<br/>[push_chunk.c]"]
  node_disorder["Disorder Estimate<br/>[compute_disorder.c]"]
end

node_user(("CLI User"))
node_stdout(("Instruction Output"))

node_user -->|"provides arguments"| node_main
node_main -->|"parses arguments"| node_parsing
node_parsing -->|"splits arguments"| node_tokens
node_parsing -->|"checks range"| node_numeric
node_parsing -->|"builds stack"| node_stack_build
node_parsing -->|"cleans errors"| node_stack_cleanup
node_main -->|"assigns indices"| node_indexing
node_main -->|"starts selection sort"| node_selector
node_selector -.-> node_adaptive
node_selector -.-> node_simple
node_selector -.-> node_chunk
node_selector -.-> node_radix
node_chunk -->|"selects chunks"| node_chunk_helper
node_chunk_helper -->|"pushes stack items"| node_push_ops
node_chunk_helper -->|"rotates stacks"| node_rotate_ops
node_chunk -->|"restores stack"| node_push_ops
node_radix -->|"moves stack items"| node_push_ops
node_radix -->|"rotates stack"| node_rotate_ops
node_push_ops -->|"prints instructions"| node_stdout
node_rotate_ops -.->|"prints instructions"| node_stdout
node_reverse_ops -->|"prints instructions"| node_stdout
node_swap_ops -.->|"prints instructions"| node_stdout
node_main -->|"frees final stack"| node_stack_cleanup

click node_main "https://github.com/alamtafe/push_swap/blob/main/main.c"
click node_parsing "https://github.com/alamtafe/push_swap/blob/main/parsing/parsing.c"
click node_tokens "https://github.com/alamtafe/push_swap/blob/main/utils/utils_parsing/ft_split.c"
click node_numeric "https://github.com/alamtafe/push_swap/blob/main/utils/utils_parsing/ft_atol.c"
click node_stack_build "https://github.com/alamtafe/push_swap/blob/main/utils/utils_lst/new_list.c"
click node_stack_cleanup "https://github.com/alamtafe/push_swap/blob/main/utils/utils_parsing/free_list.c"
click node_indexing "https://github.com/alamtafe/push_swap/blob/main/utils/utils_sorting/set_index.c"
click node_selector "https://github.com/alamtafe/push_swap/tree/main/sorting"
click node_adaptive "https://github.com/alamtafe/push_swap/blob/main/sorting/adaptive.c"
click node_simple "https://github.com/alamtafe/push_swap/blob/main/sorting/simple.c"
click node_chunk "https://github.com/alamtafe/push_swap/blob/main/sorting/medium.c"
click node_chunk_helper "https://github.com/alamtafe/push_swap/blob/main/utils/utils_sorting/push_chunk.c"
click node_radix "https://github.com/alamtafe/push_swap/blob/main/sorting/complex.c"
click node_disorder "https://github.com/alamtafe/push_swap/blob/main/utils/utils_sorting/compute_disorder.c"
click node_push_ops "https://github.com/alamtafe/push_swap/blob/main/operations/push.c"
click node_rotate_ops "https://github.com/alamtafe/push_swap/blob/main/operations/rotate.c"
click node_reverse_ops "https://github.com/alamtafe/push_swap/blob/main/operations/reverse_rotate.c"
click node_swap_ops "https://github.com/alamtafe/push_swap/blob/main/operations/swap.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_parsing,node_user toneBlue
class node_selector,node_adaptive,node_simple,node_chunk,node_radix toneAmber
class node_push_ops,node_rotate_ops,node_reverse_ops,node_swap_ops toneMint
class node_tokens,node_numeric,node_stack_build,node_stack_cleanup,node_indexing,node_chunk_helper,node_disorder toneRose
class node_stdout toneIndigo
```

## Components

### Input and Setup

- [Program Entry](https://github.com/alamtafe/push_swap/blob/main/main.c): `main.c`
- [Argument Parsing](https://github.com/alamtafe/push_swap/blob/main/parsing/parsing.c): `parsing/parsing.c`

### Sorting Strategies

- [Sort Selection](https://github.com/alamtafe/push_swap/tree/main/sorting): `sorting`
- [Adaptive Strategy](https://github.com/alamtafe/push_swap/blob/main/sorting/adaptive.c): `sorting/adaptive.c`
- [Small Sort](https://github.com/alamtafe/push_swap/blob/main/sorting/simple.c): `sorting/simple.c`
- [Chunk Sort](https://github.com/alamtafe/push_swap/blob/main/sorting/medium.c): `sorting/medium.c`
- [Radix Sort](https://github.com/alamtafe/push_swap/blob/main/sorting/complex.c): `sorting/complex.c`

### Stack Operations

- [Push Operations](https://github.com/alamtafe/push_swap/blob/main/operations/push.c): `operations/push.c`
- [Rotate Operations](https://github.com/alamtafe/push_swap/blob/main/operations/rotate.c): `operations/rotate.c`
- [Reverse Rotations](https://github.com/alamtafe/push_swap/blob/main/operations/reverse_rotate.c): `operations/reverse_rotate.c`
- [Swap Operations](https://github.com/alamtafe/push_swap/blob/main/operations/swap.c): `operations/swap.c`

### Runtime Helpers

- [Token Utilities](https://github.com/alamtafe/push_swap/blob/main/utils/utils_parsing/ft_split.c): `utils/utils_parsing/ft_split.c`
- [Number Conversion](https://github.com/alamtafe/push_swap/blob/main/utils/utils_parsing/ft_atol.c): `utils/utils_parsing/ft_atol.c`
- [Stack Construction](https://github.com/alamtafe/push_swap/blob/main/utils/utils_lst/new_list.c): `utils/utils_lst/new_list.c`
- [Memory Cleanup](https://github.com/alamtafe/push_swap/blob/main/utils/utils_parsing/free_list.c): `utils/utils_parsing/free_list.c`
- [Index Assignment](https://github.com/alamtafe/push_swap/blob/main/utils/utils_sorting/set_index.c): `utils/utils_sorting/set_index.c`
- [Chunk Selection](https://github.com/alamtafe/push_swap/blob/main/utils/utils_sorting/push_chunk.c): `utils/utils_sorting/push_chunk.c`
- [Disorder Estimate](https://github.com/alamtafe/push_swap/blob/main/utils/utils_sorting/compute_disorder.c): `utils/utils_sorting/compute_disorder.c`

### Other components

- **CLI User**
- **Instruction Output**

## Connections

- CLI User → Program Entry: provides arguments (evidence: `main.c`)
- Program Entry → Argument Parsing: parses arguments (evidence: `main.c`)
- Argument Parsing → Token Utilities: splits arguments (evidence: `parsing/parsing.c`)
- Argument Parsing → Number Conversion: checks range (evidence: `parsing/parsing.c`)
- Argument Parsing → Stack Construction: builds stack (evidence: `parsing/parsing.c`)
- Argument Parsing → Memory Cleanup: cleans errors (evidence: `parsing/parsing.c`)
- Program Entry → Index Assignment: assigns indices (evidence: `main.c`)
- Program Entry → Sort Selection: starts selection sort (evidence: `main.c`)
- Sort Selection → Adaptive Strategy
- Sort Selection → Small Sort
- Sort Selection → Chunk Sort
- Sort Selection → Radix Sort
- Chunk Sort → Chunk Selection: selects chunks (evidence: `sorting/medium.c`)
- Chunk Selection → Push Operations: pushes stack items (evidence: `utils/utils_sorting/push_chunk.c`)
- Chunk Selection → Rotate Operations: rotates stacks (evidence: `utils/utils_sorting/push_chunk.c`)
- Chunk Sort → Push Operations: restores stack (evidence: `sorting/medium.c`)
- Radix Sort → Push Operations: moves stack items (evidence: `sorting/complex.c`)
- Radix Sort → Rotate Operations: rotates stack (evidence: `sorting/complex.c`)
- Push Operations → Instruction Output: prints instructions (evidence: `operations/push.c`)
- Rotate Operations → Instruction Output: prints instructions
- Reverse Rotations → Instruction Output: prints instructions (evidence: `operations/reverse_rotate.c`)
- Swap Operations → Instruction Output: prints instructions
- Program Entry → Memory Cleanup: frees final stack (evidence: `main.c`)
