The content introduced in this article is the quick sort code in the PHP algorithm. Now I share it with you. Friends in need can also refer to it. Let’s take a look together.
$arr[$i]){ $left_array[] = $arr[$i];//比当前数小放到左边数组 } else { $right_array[] = $arr[$i];//比当前数大放到右边数组 } } //递归 调用自身 $left_array = quicksort($left_array); $reght_array = quicksort($right_array); //合并数组 返回排序好的数组 return array_merge($left_array,array($num),$reght_array); } //需要排序的数组 $arr = array(2,3,5,6,9,8,4,1); //调用递归 print_r(quicksort($arr));
Related recommendations:
The above is the detailed content of PHP algorithm quick sort. For more information, please follow other related articles on the PHP Chinese website!