python排序(插入排序) 从小到大顺序

def insert_sort(ilist):

    for i in range(len(ilist)):

        for j in range(i):

            if ilist[i] < ilist[j]:

                ilist.insert(j, ilist.pop(i))

                break

    return ilist

 
ilist = insert_sort([4,5,6,7,3,2,6,9,8])

print(ilist)

  

转载于:https://www.cnblogs.com/sea-stream/p/9689022.html

你可能感兴趣的:(python排序(插入排序) 从小到大顺序)