Quick Sort

def quick_sort(array):
    """
    Returns a sorted 'array' by quick sort algorithm via list comprehension,
    here 'array' is actually a list.
    """

    if len(array) <= 1:
        return array
    else:
        pivot = array[0]
        left = quick_sort([x for x in array[1:] if x < pivot])
        right = quick_sort([x for x in array[1:] if x >= pivot])
        return left + [pivot] + right

 

posted on 2015-03-16 13:34  AIDasr  阅读(147)  评论(0编辑  收藏  举报

导航