Python 插入排序(实现升序和降序排列)
a = [2, 4, 3, 6, 1]
#升序排列
b = len(a)
for j in range(b):
key = a[j]
i = j - 1
while i >= 0 and a[i] > key:
a[i+1] = a[i]
i -= 1
a[i+1] = key
print(a)
#降序排列
j = 1
for j in range(b):
key = a[j]
i =...
原创
2019-07-29 21:28:59 ·
1302 阅读 ·
0 评论