#任何排序的本质是交换,不同在于交换的方式
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)
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did169373