ShellSort Hill sorting

# ShellSort希尔排序_Python实现

def shell_sort(li):
    n = len(li)
    # gap间隔为长度除2
    gap = n // 2

    while gap > 0:
        for i in range(gap, n):
            while i >= gap and li[i - gap] > li[i]:
                li[i], li[i - gap] = li[i - gap], li[i]
                i -= gap
        gap //= 2
    return li


list = [1, 55, 98984, 65, 165, 356, 54, 3, 645, 74, 64, 35]

li = shell_sort(list)

print(li)

  

Hill Sort:

Shell sort used two cycles and a traverse
Hill sorting is roughly classified by the control interval is completed, then the length of a binary divider, continued contrast, continued classification then binary, and then compare
the local confusing that, when satisfied exchange but also a step forward contrast, in order to avoid the replacement value smaller than the previous step.

Guess you like

Origin www.cnblogs.com/jrri/p/12099926.html