首页 > 代码库 > python插入排序

python插入排序

def insert_sort(list):
	for i in range(len(list)):
		while i > 0 and list[i] < list[i-1]:
			temp = list[i]
			list[i] = list[i-1]
			list[i-1] = temp
			i = i-1
list = [4,4,11,23,4,5,7,9,0,111]

insert_sort(list)

list

[0, 4, 4, 4, 5, 7, 9, 11, 23, 111]