def shell_sort(alist):
"""希尔排序"""
n = len(alist)
gap = n // 2
# 插入算法执行的次数
while gap >= 1:
# 与插入算法的区别就是gap步长
for j in range(gap, n): # gap, gap+1, ..., n-1
i = j
while i > 0:
if alist[i] < alist[i - gap]:
alist[i], alist[i - gap] = alist[i - gap], alist[i]
i -= gap
else:
break
# 缩短步长
gap //= 2
if __name__ == '__main__':
lst = [45, 36, 18, 44, 66, 78, 11, 24]
shell_sort(lst)
print(lst)