#任何排序的本質是交換,不一樣在於交換的方式 numlist=[1,2,6,4,7,10,-20,77,66] print(numlist) def insertSort(numlist): for idx in range(1,len(numlist)): j = idx while j > 0 and numlist[j] < numlist[j-1]: numlist[j],numlist[j-1] = numlist[j-1],numlist[j] j = j - 1 return numlist result = insertSort(numlist) print(result)