Python实现希尔排序

lst = [i for i in range(20, 0, -1)]

length = len(lst)
r = length // 2
while r:
    for i in range(length - r):
        if lst[i] > lst[i + r]:
            lst[i], lst[i + r] = lst[i + r], lst[i]
    r = r // 2
else:
    for i in range(length - 1):
        for i in range(i, -1, -1):
            if lst[i] > lst[i + 1]:
                lst[i], lst[i + 1] = lst[i + 1], lst[i]

 

posted @ 2018-09-05 19:56  BabyJoy❤️  阅读(102)  评论(0编辑  收藏  举报