Python-希尔排序算法
def shell_sort(alist):
n = len(alist)
gap = n // 2
while gap > 0:
for i in range(gap, n):
j = i
while j >= gap:
if alist[j] < alist[j - gap]:
alist[j], alist[j - gap] = alist[j - gap], alist[j]
j -= gap
else:
break
gap //= 2
if __name__ == "__main__":
list1 = [6, 16, 22, 4, 50, 11, 20, 8]
shell_sort(list1)
print(list1)