package main
import (
"fmt"
)
func QSort(arr []int, start int, end int) {
var (
key int = arr[start]
low int = start
high int = end
)
for {
for low < high {
if arr[high] < key {
arr[low] = arr[high]
break
}
high--
}
for low < high {
if arr[low] > key {
arr[high] = arr[low]
break
}
low++
}
if low >= high {
arr[low] = key
break
}
}
if low-1 > start {
QSort(arr, start, low-1)
}
if high+1 < end {
QSort(arr, high+1, end)
}
}
func main() {
arr := []int{5, 1, 3, 0, 9, 8, 7, 4, 6}
QSort(arr, 0, len(arr)-1)
fmt.Println(arr)
}
如果转载请注明出处:http://blog.csdn.net/gophers/article/details/23346587