关于希尔排序的知识点讲解在我的博客算法分类中算法插入排序之折半插入排序详解(PHP代码实现)这里就不再重复讲解了,
这里主要为python语言实现其算法。
def shell(lis):
n = len(lis)
gap = int(n / 2)
while gap > 0:
for i in range(gap, n):
temp = lis[i]
j = i - gap
while j >= 0 and lis[j] > temp:
lis[j + gap] = lis[j]
j = j - gap
lis[j + gap] = temp
gap = int(gap / 2)
return lis
ps:这里使用的python版本为python3.
所谓勇者,是心有所惧,唯自知尔!