# grotoo/push_swap architecture

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

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

## Overview

Push_swap accepts integers as separate arguments or one space-separated argument, rejects invalid or duplicate values, then emits stack-operation instructions to sort stack A. Its main dispatch selects small-input sorters or radix sort after assigning indices; an already sorted input exits without operations. The graph also captures the stack-operation layer and the bundled printf implementation used to print instructions. Several implementation files were not excerpted, so links to their behavior are included only where the README or an excerpt supports them.

Main entry points: [`srcs/main.c`](https://github.com/grotoo/push_swap/blob/main/srcs/main.c) (Program entry and dispatch), [`srcs/sort_3.c`](https://github.com/grotoo/push_swap/blob/main/srcs/sort_3.c) (Three-item sort), [`libft/ft_printf.c`](https://github.com/grotoo/push_swap/blob/main/libft/ft_printf.c) (Format dispatch), [`srcs/radix.c`](https://github.com/grotoo/push_swap/blob/main/srcs/radix.c) (Radix sort)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_input["Input and validation"]
  node_entry["Program entry and dispatch<br/>[main.c]"]
  node_split["Argument splitting<br/>[ft_split.c]"]
  node_validation["Input validation<br/>[check.c]"]
  node_integer["Integer conversion<br/>[ft_atoi.c]"]
  node_list["Stack construction<br/>[add.c]"]
  node_duplicates["Duplicate detection<br/>[push_swap_utils.c]"]
end

subgraph group_sorting["Sorting strategies"]
  node_sorted["Sorted check<br/>[is_sorted.c]"]
  node_indexing["Rank indexing<br/>[set_index.c]"]
  node_small3["Three-item sort<br/>[sort_3.c]"]
  node_small4["Four-item sort<br/>[sort_4.c]"]
  node_small5["Five-item sort<br/>[sort_5.c]"]
  node_radix["Radix sort<br/>[radix.c]"]
end

subgraph group_operations["Stack operations"]
  node_swap["Swap operations<br/>[swap.c]"]
  node_push["Push operations<br/>[push.c]"]
  node_rotate["Rotate operations<br/>[rotate.c]"]
  node_reverse["Reverse rotations<br/>[reverse_rotate.c]"]
end

subgraph group_output["Output support"]
  node_printf["Format dispatch<br/>[ft_printf.c]"]
  node_printf_handlers["Format handlers<br/>[ft_printf_d.c]"]
  node_printf_api["Formatter interface<br/>[libft.h]"]
end

node_user(("User"))

node_user -->|"provides arguments"| node_entry
node_entry -->|"splits single argument"| node_split
node_entry -->|"validates tokens"| node_validation
node_entry -->|"converts tokens"| node_integer
node_entry -->|"adds values"| node_list
node_entry -->|"checks duplicates"| node_duplicates
node_entry -->|"checks order"| node_sorted
node_entry -->|"assigns ranks"| node_indexing
node_entry -->|"dispatches at three"| node_small3
node_entry -->|"dispatches at four"| node_small4
node_entry -->|"dispatches at five"| node_small5
node_entry -->|"dispatches above five"| node_radix
node_small3 -->|"invokes swaps"| node_swap
node_small3 -->|"invokes rotations"| node_rotate
node_small3 -->|"invokes reverse rotations"| node_reverse
node_radix -->|"rotates set bits"| node_rotate
node_radix -->|"moves bit groups"| node_push
node_swap -->|"prints instruction"| node_printf
node_printf -->|"dispatches formats"| node_printf_handlers
node_printf -->|"uses declarations"| node_printf_api
node_printf -->|"prints result"| node_user

click node_entry "https://github.com/grotoo/push_swap/blob/main/srcs/main.c"
click node_split "https://github.com/grotoo/push_swap/blob/main/srcs/ft_split.c"
click node_validation "https://github.com/grotoo/push_swap/blob/main/srcs/check.c"
click node_integer "https://github.com/grotoo/push_swap/blob/main/srcs/ft_atoi.c"
click node_list "https://github.com/grotoo/push_swap/blob/main/srcs/add.c"
click node_duplicates "https://github.com/grotoo/push_swap/blob/main/srcs/push_swap_utils.c"
click node_sorted "https://github.com/grotoo/push_swap/blob/main/srcs/is_sorted.c"
click node_indexing "https://github.com/grotoo/push_swap/blob/main/srcs/set_index.c"
click node_small3 "https://github.com/grotoo/push_swap/blob/main/srcs/sort_3.c"
click node_small4 "https://github.com/grotoo/push_swap/blob/main/srcs/sort_4.c"
click node_small5 "https://github.com/grotoo/push_swap/blob/main/srcs/sort_5.c"
click node_radix "https://github.com/grotoo/push_swap/blob/main/srcs/radix.c"
click node_swap "https://github.com/grotoo/push_swap/blob/main/srcs/swap.c"
click node_push "https://github.com/grotoo/push_swap/blob/main/srcs/push.c"
click node_rotate "https://github.com/grotoo/push_swap/blob/main/srcs/rotate.c"
click node_reverse "https://github.com/grotoo/push_swap/blob/main/srcs/reverse_rotate.c"
click node_printf "https://github.com/grotoo/push_swap/blob/main/libft/ft_printf.c"
click node_printf_handlers "https://github.com/grotoo/push_swap/blob/main/libft/ft_printf_d.c"
click node_printf_api "https://github.com/grotoo/push_swap/blob/main/libft/libft.h"

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_entry,node_split,node_validation,node_integer,node_list,node_duplicates,node_user toneBlue
class node_sorted,node_indexing,node_small3,node_small4,node_small5,node_radix toneAmber
class node_swap,node_push,node_rotate,node_reverse toneMint
class node_printf,node_printf_handlers,node_printf_api toneRose
```

## Components

### Input and validation

- [Program entry and dispatch](https://github.com/grotoo/push_swap/blob/main/srcs/main.c): `srcs/main.c`
- [Argument splitting](https://github.com/grotoo/push_swap/blob/main/srcs/ft_split.c): `srcs/ft_split.c`
- [Input validation](https://github.com/grotoo/push_swap/blob/main/srcs/check.c): `srcs/check.c`
- [Integer conversion](https://github.com/grotoo/push_swap/blob/main/srcs/ft_atoi.c): `srcs/ft_atoi.c`
- [Stack construction](https://github.com/grotoo/push_swap/blob/main/srcs/add.c): `srcs/add.c`
- [Duplicate detection](https://github.com/grotoo/push_swap/blob/main/srcs/push_swap_utils.c): `srcs/push_swap_utils.c`

### Sorting strategies

- [Sorted check](https://github.com/grotoo/push_swap/blob/main/srcs/is_sorted.c): `srcs/is_sorted.c`
- [Rank indexing](https://github.com/grotoo/push_swap/blob/main/srcs/set_index.c): `srcs/set_index.c`
- [Three-item sort](https://github.com/grotoo/push_swap/blob/main/srcs/sort_3.c): `srcs/sort_3.c`
- [Four-item sort](https://github.com/grotoo/push_swap/blob/main/srcs/sort_4.c): `srcs/sort_4.c`
- [Five-item sort](https://github.com/grotoo/push_swap/blob/main/srcs/sort_5.c): `srcs/sort_5.c`
- [Radix sort](https://github.com/grotoo/push_swap/blob/main/srcs/radix.c): `srcs/radix.c`

### Stack operations

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

### Output support

- [Format dispatch](https://github.com/grotoo/push_swap/blob/main/libft/ft_printf.c): `libft/ft_printf.c`
- [Format handlers](https://github.com/grotoo/push_swap/blob/main/libft/ft_printf_d.c): `libft/ft_printf_d.c`
- [Formatter interface](https://github.com/grotoo/push_swap/blob/main/libft/libft.h): `libft/libft.h`

### Other components

- **User**

## Connections

- User → Program entry and dispatch: provides arguments (evidence: `README.md`)
- Program entry and dispatch → Argument splitting: splits single argument (evidence: `srcs/main.c`)
- Program entry and dispatch → Input validation: validates tokens (evidence: `srcs/main.c`)
- Program entry and dispatch → Integer conversion: converts tokens (evidence: `srcs/main.c`)
- Program entry and dispatch → Stack construction: adds values (evidence: `srcs/main.c`)
- Program entry and dispatch → Duplicate detection: checks duplicates (evidence: `srcs/main.c`)
- Program entry and dispatch → Sorted check: checks order (evidence: `srcs/main.c`)
- Program entry and dispatch → Rank indexing: assigns ranks (evidence: `srcs/main.c`)
- Program entry and dispatch → Three-item sort: dispatches at three (evidence: `srcs/main.c`)
- Program entry and dispatch → Four-item sort: dispatches at four (evidence: `srcs/main.c`)
- Program entry and dispatch → Five-item sort: dispatches at five (evidence: `srcs/main.c`)
- Program entry and dispatch → Radix sort: dispatches above five (evidence: `srcs/main.c`)
- Three-item sort → Swap operations: invokes swaps (evidence: `srcs/sort_3.c`)
- Three-item sort → Rotate operations: invokes rotations (evidence: `srcs/sort_3.c`)
- Three-item sort → Reverse rotations: invokes reverse rotations (evidence: `srcs/sort_3.c`)
- Radix sort → Rotate operations: rotates set bits (evidence: `srcs/radix.c`)
- Radix sort → Push operations: moves bit groups (evidence: `srcs/radix.c`)
- Swap operations → Format dispatch: prints instruction (evidence: `srcs/swap.c`)
- Format dispatch → Format handlers: dispatches formats (evidence: `libft/ft_printf.c`)
- Format dispatch → Formatter interface: uses declarations (evidence: `libft/ft_printf.c`)
- Format dispatch → User: prints result (evidence: `README.md`)
