插入呢
同一个数组跑插入排序。运行下面这段程序:
def insertion_stat(a):
b = list(a)
cmps = 0
moves = 0
for i in range(1, len(b)):
key = b[i]
j = i - 1
while j >= 0:
cmps += 1
if b[j] <= key:
break
b[j + 1] = b[j]
moves += 1
j -= 1
b[j + 1] = key
return cmps, moves
c, m = insertion_stat([17, 24, 15, 13, 23])
print(str(c) + "/" + str(m))
全部评论