def insert_sort(li):
for i in range(1, len(li)):
temp = li[i]
j = i - 1
while j >= 0 and temp < li[j]:
li[j + 1] = li[j]
j -= 1
li[j + 1] = temp
print(li)
li = [3, 4, 2, 1, 5, 7, 9, 8, 6]
insert_sort(li)
插入排序——python
最新推荐文章于 2024-08-15 01:55:01 发布