# 希尔排序可以理解为不同间隔步的插排
def shellSort(aList):
subListCount = len(aList) // 2
while subListCount > 0:
for startPosition in range(subListCount):
gapInsertSort(aList, startPosition, subListCount)
print("After increments of size", subListCount, "The list is", aList)
subListCount = subListCount // 2
def gapInsertSort(aList, start, gap):
for i in range(start,len(aList), gap):
currentValue = aList[i]
position = i
while position > 0 and currentValue < aList[position - gap]:
aList[position] = aList[position - gap]
position -= gap
aList[position] = currentValue
alist = [54, 26, 93, 17, 77, 31, 44, 55, 20]
shellSort(alist)
print(alist)