python 算法

快速排序算法

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)

  

原文地址:https://www.cnblogs.com/chenxinming-top/p/9000380.html