golang 快速排序算法
package main
import "fmt"
var arr = []int{7, 6, 8, 3, 5, 2, 4, 9, 1, 0}
var tmpArr = make([]int, len(arr))
func main() {
fmt.Println(arr)
quickSort(arr, 0, len(arr)-1)
fmt.Println(arr)
}
func quickSort(arr []int, begin, end int) {
if begin < end {
key := arr[begin]
i, j := begin, end
for i < j {
for i < j && key < arr[j] {
j--
}
if i < j {
arr[i] = arr[j]
i++
}
for i < j && key > arr[i] {
i++
}
if i < j {
arr[j] = arr[i]
j--
}
}
arr[i] = key
quickSort(arr, begin, i-1)
quickSort(arr, i+1, end)
}
}