快速排序

def quick_sort(lists, left, right):
    if left >= right:
        return lists
    pivot = lists[left]
    low = left
    high = right
    while left < right:
        while left < right and lists[right] >= pivot:
            right -= 1
        while left < right and lists[left] <= pivot:
            left += 1
        lists[left],lists[right] = lists[right],lists[left]
    lists[low],lists[right] = lists[right],lists[low]
    
        
    
    lists[right] = pivot
    quick_sort(lists, low, left - 1)
    quick_sort(lists, left + 1, high)
    return lists

A = [6,1,2,6,2,7,9,3,4,5,10,8]
quick_sort(A,0,len(A)-1)
print(A)

你可能感兴趣的:(快速排序)