# 想象成打扑克牌摸一张牌后按大小插入相应位置 def insert_sort(lst): for i in range(1, len(lst)): tmp = lst[i] j = i - 1 while j >=0 and lst[j] > tmp: lst[j+1] = lst[j] j -= 1 lst[j+1] = tmp print(lst)
# 想象成打扑克牌摸一张牌后按大小插入相应位置 def insert_sort(lst): for i in range(1, len(lst)): tmp = lst[i] j = i - 1 while j >=0 and lst[j] > tmp: lst[j+1] = lst[j] j -= 1 lst[j+1] = tmp print(lst)