排序算法——快速排序

package main

func quickSort(lst []int, low, high int) {
	if low < high {
		privot := partation(lst, low, high)
		quickSort(lst, low, privot)
		quickSort(lst, privot+1, high)
	}
}

func partation(lst []int, low, high int)  int {
	privotKey := lst[low]
	for low < high {
		for low < high && privotKey <= lst[high] {
			high--
		}
		lst[low], lst[high] = lst[high], lst[low]
		for low < high && lst[low] < privotKey {
			low++
		}
		lst[low], lst[high] = lst[high], lst[low]
	}
	return low
}

你可能感兴趣的:(算法)