def sort(arry):
for i in range(1, len(arry)):
x = arry[i]
j = i
while j > 0 and arry[j-1] > x:
arry[j] = arry[j-1]
j -= 1
arry[j] = x
return arry
测试:a = [3,2,1]
a = sort(a)
print(a)
插入排序另一种实现方法报错,求盟友解答:
截图为课本提供的实现方法,我认为报错的原因是:此方法只能用于字符串之间的排序