python实现插入排序
import random
def insert_sort(li): for i in range(1, len(li)): j = i - 1 tmp = li[i] while j >= 0 and li[j] > tmp: li[j+1] = li[j] j -= 1 li[j+1] = tmp li = list(range(10000)) random.shuffle(li) insert_sort(li)
import random
def insert_sort(li): for i in range(1, len(li)): j = i - 1 tmp = li[i] while j >= 0 and li[j] > tmp: li[j+1] = li[j] j -= 1 li[j+1] = tmp li = list(range(10000)) random.shuffle(li) insert_sort(li)