go快速排序

/**
快速排序
 */

func QuickSort(nums []int, start, end int)  {
	if start < end {
		i, j := start, end
		mid := nums[(start + end) / 2]
		for i <+ j {
			for nums[i] < mid {
				i++
			}
			for nums[j] < mid {
				j--
			}
			if i <= j {
				nums[i], nums[j] = nums[j], nums[i]
				i++
				j--
			}
		}
		if start < j {
			QuickSort(nums, start, j)
		}
		if end > i {
			QuickSort(nums, i, end)
		}
	}
}

 

点赞