This commit is contained in:
krahets
2023-03-12 18:46:03 +08:00
parent 209d82a8cc
commit f6b9a75c8f
23 changed files with 406 additions and 359 deletions
+3 -3
View File
@@ -63,12 +63,12 @@ comments: true
=== "Python"
```python title="insertion_sort.py"
def insertion_sort(nums):
def insertion_sort(nums: List[int]) -> None:
""" 插入排序 """
# 外循环:base = nums[1], nums[2], ..., nums[n-1]
for i in range(1, len(nums)):
base = nums[i]
j = i - 1
base: int = nums[i]
j: int = i - 1
# 内循环:将 base 插入到左边的正确位置
while j >= 0 and nums[j] > base:
nums[j + 1] = nums[j] # 1. 将 nums[j] 向右移动一位