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

快速排序

时间:2019-03-28 20:33:19      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:ret   else   def   快速排序   sort   quick   python   return   gre   

def quicksort(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>pivot]
    return quicksort(less)+[pivot]+quicksort(greater)

print quicksort([10,5,2,3])

快速排序

标签:ret   else   def   快速排序   sort   quick   python   return   gre   

原文地址:https://www.cnblogs.com/Jmmm/p/10617420.html

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