M

merge_sort_mermaid-js.github.io

Категория проекта: Ожидает модерации

merge_sort_mermaid-js.github.io_level_up_graphiqs_elements

graph TD;  
A(["merge_sort(list)"]):::start --> B["length = len(list)"]:::process  
B --> C{"length == 1?"}:::decision  
C --> |true| D["return list"]
C --> |false| E["mid = length // 2"]:::process  
E --> F["left = merge_sort(list[:mid])"]:::process  
F --> G["right = merge_sort(list[mid:])"]:::process  
G --> H["return merge(left, right)"]:::process  

%% Вспомогательная функция 
H --> I["merge(left, right)"]:::start 
I --> J["output = []"]:::process  
J --> K["i = j = 0"]:::process  
K --> L{"i < len(left) and j < len(right)?"}:::decision  
L --> |true| M{"left[i] < right[j]?"}:::decision  
M --> |true| N["output.append(left[i])"]:::process  
N --> O["i += 1"]:::process  
M --> |false| P["output.append(right[j])"]:::process  
P --> Q["j += 1"]:::process  
L --> |false| R["output.extend(left[i:])"]:::process  
R --> S["output.extend(right[j:])"]:::process  
S --> T["return output"]

%% Главная функция 
T --> U["main()"]:::start  
U --> V["unsorted = [99, 0, 5, 20, ...]"]:::process  
V --> W["sorted = merge_sort(unsorted)"]:::process  
W --> X["print(sorted)"]:::process  
X --> Y["unsorted = [3, 9, 2, 1]"]:::process  
Y --> Z["sorted = merge_sort(unsorted)"]:::process  
Z --> AA["print(sorted)"]:::process  

%% Определение стилей для классов
classDef start fill:#ffcccb,stroke:#333,stroke-width:2px;
classDef process fill:#add8e6,stroke:#333,stroke-width:2px;
classDef decision fill:#ffe4b5,stroke:#333,stroke-width:2px;
classDef en fill:#90ee90,stroke:#333,stroke-width:2px;