快速排序(golang)

package main

import "fmt"

func Parrten(list []int,l,r int)int{
	base := r
	for l < r{
		for(l<=r && list[l]<list[base]){l++}
		for(l<r && list[r]>list[base]){r--}
		list[l],list[base] = list[base],list[l]
	}
	return l
}


func QuickSort(list []int,l int,r int){
	if l < r {
		mid := Parrten(list,l,r)
		//fmt.Println(mid)
		QuickSort(list, l, mid-1)
		QuickSort(list, mid+1, r)
	}
}


func main(){
	list := []int{5, 6, 4, 3, 7,99,33,8}
	QuickSort(list,0,len(list)-1)
	fmt.Println(list)
}
上一篇:[TJOI2019]唱、跳、rap和篮球


下一篇:Quicksort Python排序麻烦