使用插入排序实现排序(废话)
python
def insertSort(list): for i in range(1,len(list)): j = i-1 temp = list[i] while (j>=0) & (temp < list[j]): list[j+1] = list[j] j = j-1 list[j+1]=temp return list list = [6,2,7,4,3] print insertSort(list) #[2, 3, 4, 6, 7]
使用插入排序实现排序(废话)
python
def insertSort(list): for i in range(1,len(list)): j = i-1 temp = list[i] while (j>=0) & (temp < list[j]): list[j+1] = list[j] j = j-1 list[j+1]=temp return list list = [6,2,7,4,3] print insertSort(list) #[2, 3, 4, 6, 7]