python实现插入排序

def insert_sort(alist):
    for j in range(1,len(alist)):
        for i in range(j,0,-1):
            if alist[i] < alist[i - 1]:
                alist[i], alist[i - 1] = alist[i - 1], alist[i]
            else:
                break
if __name__ == '__main__':
    li = [6, 5, 8, 45, 46, 98]
    insert_sort(li)
    print(li)

结果python实现插入排序_第1张图片

你可能感兴趣的:(python)