```go
func quickSort(arr []int, p, r int) {
if p < r {
q := partition(arr, p, r)
quickSort(arr, p, q-1)
quickSort(arr, q+1, r)
}
}
func partition(arr []int, p, r int) int {
//把最后一个值赋给x
x := arr[r]
i := p - 1
for j := p; j <= r-1; j++ {
if arr[j] <= x {
i++
arr[i], arr[j] = arr[j], arr[i]
}
}
arr[i+1], arr[r] = arr[r], arr[i+1]
return i + 1
}
```
有疑问加站长微信联系(非本文作者))