1. 程式人生 > >python數據結構之希爾排序

python數據結構之希爾排序

-c 技術 alt def play pan order for eight

技術分享圖片

def shell_sort(alist):
    n=len(alist)
    gap= int(n / 2) #步長
    while gap>0:
        for i in range(gap,n):
            j=i
            while j>=gap and alist[j-gap] > alist[j]:
                alist[j-gap],alist[j]=alist[j],alist[j-gap] #交換值
                j-=gap
        gap=int(gap/2)  #
新的步長 alist=[11,33,44,55,66,9,72,86,93,10,1,0,2] shell_sort(alist) print(alist)

python數據結構之希爾排序