#### Heading 4 golang版
```go
func main() {
arr := []int{3,12, 3, 3, 121, 454, 66, 33, 525, 56, 818, 444, 655, 5, 87, 652, 222, 16, 55, 43144}
result:= quickSort(arr[:])
fmt.Println(result)
}
func quickSort(a []int) []int {
if len(a) == 1 {
return a
}
//样本数字
flag := a[0]
//比flag 小的
left := make([]int, 0)
//比flag大的
right := make([]int, 0)
//相同值
same := make([]int, 0)
for i := 1; i < len(a); i++ {
if a[i] < flag {
left = append(left, a[i])
}
if a[i] > flag {
right = append(right, a[i])
}
if a[i] == flag {
same = append(same, a[i])
}
}
if len(left) > 0 {
left = quickSort(left)
}
if len(right) > 0 {
right = quickSort(right)
}
return append(append(append(left, same...), flag), right...)
}
```
###结果:
```
[3 3 3 5 12 16 33 55 56 66 87 121 222 444 454 525 652 655 818 43144]
```
#### Heading 4 PHP版
```php
public function index($arr)
{
$arr = [32, 1, 2, 13, 42, 33, 34, 56, 33, 23, 67, 23, 365, 87665, 54, 68, 3];
$result = $this->quickSort($arr);
print_r(result );
}
public function quickSort($arr)
{
if (count($arr) <= 1) {
return $arr;
}
$middle = $arr[0];
$left = $right = $mid = [];
for ($i = 1; $i < count($arr); $i++) {
if ($middle > $arr[$i]) {
$left[] = $arr[$i];
} elseif ($middle == $arr[$i]) {
$mid[] = $arr[$i];
} elseif ($middle < $arr[$i]) {
$right[] = $arr[$i];
}
}
$left = $this->quickSort($left);
$mid = $this->quickSort($mid);
$right = $this->quickSort($right);
return array_merge($left, $mid, [$middle], $right);
}
```
###结果
```
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 13
[4] => 23
[5] => 23
[6] => 32
[7] => 33
[8] => 33
[9] => 34
[10] => 42
[11] => 54
[12] => 56
[13] => 67
[14] => 68
[15] => 365
[16] => 87665
)
```
有疑问加站长微信联系(非本文作者))