快速排序--python实现

def find_index(nums, low, high):
    key = nums[low]
    while low < high:
        while low < high and key <= nums[high]:
            high -= 1
        while low < high and key > nums[high]:
             nums[low] = nums[high]
             low += 1
             nums[high] = nums[low]
    nums[low] = key
    return low

def quick_sort(nums, low, high):
    if low < high:
        index = find_index(nums)
        quick_sort(nums, low, index)
        quick_sort(nums, index+1, high)

find_index()是为了找到nums中某一个值在nums中应该的位置

    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞