算法导论初学之插入排序

arr = [8,2,4,7,3,6]
length = len(arr)
for j in range(1,length):
    key = arr[j]
    i = j-1
    while i>-1 and arr[i]>key:
        arr[i+1] = arr[i]
        i = i-1
    arr[i+1] = key
print(arr)

 

posted @ 2019-03-06 01:46  菜の可怜  阅读(129)  评论(0编辑  收藏  举报