python实现排序算法
发布时间:2016-12-28 来源:查字典编辑
摘要:复制代码代码如下:definsertion_sort(n):iflen(n)==1:returnnb=insertion_sort(n[1:...
复制代码 代码如下:
def insertion_sort(n):
if len(n) == 1:
return n
b = insertion_sort(n[1:])
m = len(b)
for i in range(m):
if n[0] <= b[i]:
return b[:i]+[n[0]]+b[i:]
return b + [n[0]]
l = [1,3,4,2,6,7,9,7,12,11,789,345,456]
print insertion_sort(l)
d = input('l=')
print insertion_sort(d)
a = input('y:')