码迷,mamicode.com
首页 > 编程语言 > 详细

快速排序

时间:2019-01-16 14:22:54      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:turn   ret   class   lse   code   gre   pivot   else   print   

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]

 

快速排序

标签:turn   ret   class   lse   code   gre   pivot   else   print   

原文地址:https://www.cnblogs.com/fushou/p/10276673.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!