Home > Article > Backend Development > PHP quicksort
<?php function quickSort($left,$right,$sort_arr = null){ static $arr; if(!empty($sort_arr)){ $arr = $sort_arr; } if($left >= $right){ return; } $mark_num = $arr[$left]; $mark_k = $left; $i = $left+1; $j = $right; while($i != $j){ //左移判断 while($arr[$j] > $mark_num && $j > $i){ $j--; } //右移判断 while($arr[$i] <= $mark_num && $i < $j){ $i++; } $tmp = $arr[$i]; $arr[$i] = $arr[$j]; $arr[$j] = $tmp; } if($arr[$i] < $mark_num){ $arr[$mark_k] = $arr[$i]; $arr[$i] = $mark_num; } quickSort($left,$i-1); quickSort($i+1,$right); return $arr; }
The above introduces the PHP quick sort method, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.