php涓疄鐜 Board揩掺掍挌捐掓场掺掎簭_PHP揁欑▼ | 宁涔嫔

WBOY
Release: 2016-07-14 10:11:45
Original
1690 people have browsed it

Jian帓

function quicksort($str){
if(count($str)<=1) return $str;//濡悛灉涓暟涓嶅ぇ浜庝竴锛倀濿掺ヨ繑锲?br /> $key=$str[0];//鍙栦竴涓€緷纴绋嶅嶗搢ㄦ浵姣懇锛?br /> $left_arr=array();
$right_arr=array();
for($i=1;$i if($str[$i]<=$key)
$left_arr[]=$str[$i];
else
$right_arr[]=$str[$i];
}
$left_arr=quicksort($left_arr);//杩涜阃掎綊甛?br /> $right_arr=quicksort($right_arr);
return array_merge($left_arr,array($key),$right_arr);//描嗗狠擓彸镄啫€揎悎鞞枚暓涓€涓暟缁勶绂
}//浠ヤ笅鏄祴璇?br /> $str=array(5,3,8,2,5,9,7,2,1,4,0);
print_r(quicksort($str));
?>
鍐掓场鎺掑簭

function bubbingSort(array $array)
{
for($i=0, $len=count($array)-1; $i<$len; ++$i)
{
for($j=$len; $j>$i; --$j)
{
if($array[$j] < $array[$j-1])
{
$temp = $array[$j];
$array[$j] = $array[$j-1];
$array[$j-1] = $temp;
}
}
}
return $array;
}

print '

';<br>
print_r(bubbingSort(array(1,4,22,5,7,6,9)));<br>
print '
';


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477279.htmlTechArticle臇帓?php function quicksort($str){ if(count($str)=1) return $ str;//捙悛灉涓暟涓嶅ぇ溜庴锛倀洿掺ヨ繑锲?$key=$str[0];//鍙栦竴涓€玷纴绋嶅悗鐢ㄦ潵婣懇 Ji锛?$left_arr=array();...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!