func QuickSort(a []int, p, r int) { if p < r { q := Partition(a, p, r) QuickSort(a, p, q-1) QuickSort(a, p+1, r) } } func Partition(a []int, p, r int) int { x := a[r] i := p - 1 for j := p; j < r-1; j++ { if a[j] <= x { i = i + 1 a[i], a[j] = a[j], a[i] } } i = i + 1 a[i], a[r] = a[r], a[i] return i }
快速排序的golang实现
最新推荐文章于 2024-07-17 18:39:05 发布