快排

func quickSort(nums []int,left int,right int ){

    if left < right {
         p := park(nums,left,right)
         quickSort(nums,left,p-1)
         quickSort(nums,p+1,right)
    }
}
func park(nums []int,left int,right int) int{
    i := left - 1

    for j:= left ; j <= right ; j++   {
        if nums[j] <= nums[right]{
            i++
            temp := nums[i]
            nums[i] = nums[j]
            nums[j] = temp
        }
    }
    i++
    temp := nums[i]
    nums[i] = nums[right]
    nums[right] = temp
    return i
}

 

posted @ 2019-09-20 19:12  式微胡不归  阅读(116)  评论(0编辑  收藏  举报