Python实现希尔排序 -- 2019-08-07 11:27:14

原创: http://106.13.73.98/__/46/

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]

原创: http://106.13.73.98/__/46/

猜你喜欢

转载自www.cnblogs.com/gqy02/p/11314270.html
今日推荐