Quicksort is a kind of sorting algorithm with high efficiency, and its idea is mainly recursive
package main
import "fmt"
func QuickSort(left int, right int, arr *[6]int) {
l := left
r := right
pivot := arr[(left + right) / 2]
for ; l < r; {
for ; arr[l] < pivot; {
l++
}
for ; arr[r] > pivot; {
r--
}
if l >= r {
break
}
arr[r], arr[l] = arr[l], arr[r]
if arr[l] == pivot {
r--
}
if arr[r] == pivot {
l++
}
}
if l==r {
l++
r--
}
if left < r {
QuickSort(left, r, arr)
}
if right > l {
QuickSort(l, right, arr)
}
}
func main(a){
arr := [6]int{9 -.78.0.23.- 57.70}
fmt.Println(arr)
QuickSort(0.len(arr) - 1, &arr)
fmt.Println(arr)
}
Copy the code
Output:
[-9 78 0 23-57 70] [-57 -9 0 23 70 78]Copy the code