0
点赞
收藏
分享

微信扫一扫

11_shell_sort_希尔排序

def insert_sort_gap(li, gap):

    for i in range(gap, len(li)):
        temp = li[i]
        j = i - gap

        while j >= 0 and li[j] > temp:
            li[j + gap] = li[j]
            j -= gap
        li[j + gap] = temp


def shell_sort(li):

    d = len(li) // 2

    while d >= 1:
        insert_sort_gap(li, d)
        d //= 2
举报

相关推荐

0 条评论