Home >Backend Development >Python Tutorial >python实现排序算法

python实现排序算法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-16 08:45:15983browse

复制代码 代码如下:

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]             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:')

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn