插入排序
插入排序
Aristore像是手动整理一副牌。
实践
1 | def InsertionSort(nums): # 像是手动整理一副牌 |
流程图
graph TD Start["Start: Initialize nums as a copy of input"] --> A["Iterate over nums starting from index 1"] A --> B["Set base = nums[i]"] B --> C["Set j = i - 1"] C --> D{"Is j >= 0?"} D -->|No| E["Insert base at position j + 1"] E --> F["Return sorted nums"] D -->|Yes| G{"Is nums[j] >= base?"} G -->|No| E G -->|Yes| H["Shift nums[j] to nums[j + 1]"] H --> I["Decrement j"] I --> D
评论
匿名评论隐私政策