python 快速排序

平均时间复杂度O(nlogn)

最坏情况O(n^2)

def quick(array):
    if len(array)<2:
        return array
    else:
        pivot_index = 0
        pivot = array[pivot_index]
        less_part = [i for i in array[pivot_index+1:]if i <pivot ]
        great_part = [i for i in array[pivot_index+1:]if i>pivot]
        return quick(less_part) + [pivot]+quick(great_part)
a = [7,24,3,12,44,6]
print(quick(a))

  

posted @ 2018-12-04 14:02  黄溢  阅读(189)  评论(0编辑  收藏  举报