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)
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)