希尔排序

 

data = [16, 25, 39, 27, 12, 8, 45, 63]

SIZE = len(data)


def show(data):
    for i in range(len(data)):
        print(data[i], end=' ')
    print()


def shell(data, size):
    jmp = size // 2
    while jmp != 0:
        for i in range(jmp, size):
            temp = data[i]
            j = i - jmp
            while j >= 0 and data[j] > temp:
                data[j + jmp] = data[j]
                j = j - jmp
            data[j + jmp] = temp
        jmp = jmp // 2


shell(data, SIZE)
show(data)

 

posted @ 2019-03-07 12:30  jj千寻  阅读(75)  评论(0编辑  收藏  举报