首页 > 技术文章 > python 算法

chenxinming-top 2018-05-06 23:40 原文

快速排序算法

1. 把array =[9,5,12,4,63,1,3,5,6,15,32] 按照从小到大排序

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)

  

推荐阅读