快速排序

def qsort(array):
    if len(array)<2:
        return array
    else:
        pivot = array[0]
        less=[i for i in array[1:] if i <=pivot]
        greater = [i for i in array[1:] if i > pivo
        return qsort(less) +[pivot]+qsort(greater)

In [4]: print(qsort([5,4,6,3,2,0,1]))
[0, 1, 2, 3, 4, 5, 6]

 

posted @ 2019-01-16 14:01  fosonR  阅读(186)  评论(0编辑  收藏  举报