快速排序

快速排序

def quick_sort(data, left, right):

        if left < right:

            mid = partition(data, left, right)
    
            quick_sort(data, left, mid - 1)
    
            quick_sort(data, mid + 1, right)
def partition(data, left, right):

    tmp = data[left]
    
    while left < right:
    
        while left < right and data[right] >= tmp:
        
            right -= 1
            
        data[left] = data[right]
        
        while left < right and data[left] <= tmp:
        
            left += 1
            
        data[right] = data[left]
        
    data[left] = tmp
    
    return left
posted @ 2017-03-10 11:24  Dus  阅读(139)  评论(0编辑  收藏  举报