# coding:utf-8
__author__ = 'taohao'
"""
shell sort is improving the performance of the insert sort
"""
def shell_sort(array):
gap = len(array)/2
while gap > 0:
i = gap
while i < len(array):
tem = array[i]
j = i
while tem < array[j-gap] and j >= gap:
array[j] = array[j-gap]
j -= gap
array[j] = tem
i += 1
gap /= 2
if __name__ == '__main__':
array = [19, 3, 6, 99, 80, 39, 4, 2, 27, 50, 6, 75, 201, 98, 28, 91]
shell_sort(array)
print array
shell 排序
最新推荐文章于 2022-08-21 20:51:14 发布