<?php function Partition(&$arr,$low,$high) { $_t=$arr[$low]; while($low<$high) { //注意第二个限制条件,不然如果一直都是大于会超过数组下标 while($arr[$high]>$_t&&$high>$low) --$high; $arr[$low]=$arr[$high]; while($arr[$low]<$_t&&$low<$high) ++$low; $arr[$high]=$arr[$low]; } $arr[$low]=$_t; return $low; } function Qsort(&$arr,$low,$high) { if($low<$high) { $mid=Partition($arr,$low,$high); Qsort($arr,$low,$mid-1); Qsort($arr,$mid+1,$high); } } $a=array(9,8,7,10,11,4,3,2,1); Qsort($a,0,8); var_dump($a);
Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.
The above has introduced quick sorting Qsort, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.