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