insert sort in Python

insert sort

def insert_sort(list_02):
    for j in range(1, len(list_02)):
        for i in range(j, 0, -1):
            if list_02[i] < list_02[i - 1]:
                list_02[i], list_02[i - 1] = list_02[i - 1], list_02[i]
                i -= 1
            else:
                break

def main():
    list_01 = [2, 4, 55, 1, 6, 28, 54, 55, 19, 95, 48, 65]
    insert_sort(list_01)
    print(list_01)

if __name__ == '__main__':
    main()


---------------results of enforcement----------
[1, 2, 4, 6, 19, 28, 48, 54, 55, 55, 65, 95]

-----------------------------------------------

没有更多推荐了,返回首页