[AppleScript] 纯文本查看 复制代码
def shell_sort(alist): n = len(alist) # 初始步⻓ gap = n / 2 while gap > 0: # 按步⻓进⾏插⼊排序 for i in range(gap, n): j = i # 插⼊排序 while j>=gap and alist[j-gap] > alist[j]: alist[j-gap], alist[j] = alist[j], alist[j-ga p] j -= gap # 得到新的步⻓
gap = gap / 2
alist = [54,26,93,17,77,31,44,55,20] shell_sort(alist) print(alist)