def shell_sort(alist):
n = len(alist)
gap = n // 2
while gap >= 1:
for j in range(gap, n):
i = j
while (i - gap) >= 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__':
li = [6, 5, 8, 45, 46, 98]
shell_sort(li)
print(li)
结果