php实现各种排序算法

一、冒泡

function bubbleSort($numarr) {
	$arrlen = count($numarr);
	echo $arrlen;
	for ($i = 0; $i < $arrlen - 1; $i++) {
		for ($j = $i + 1; $j < $arrlen; $j++) {
			if ($numarr[$j] < $numarr[$i]) {
				$temp = $numarr[$i];
				$numarr[$i] = $numarr[$j];
				$numarr[$j] = $temp;
			}
		}
	}
	return $numarr;
}

$numarr = array(12, 23, 4, 3, 32, 12, 3, 2);
print_r(bubbleSort($numarr));

广告


未完待续。。。

大宝日记版权所有,转载必究,博客地址http://www.sundabao.com/php%E5%AE%9E%E7%8E%B0%E5%90%84%E7%A7%8D%E6%8E%92%E5%BA%8F%E7%AE%97%E6%B3%95/。

JackSun

JackSun

I'm a coder.

You may also like...

2 Responses

  1. www.bundary.com says:

    楼主你的代码高亮插件是什么啊

  2. JackSun 孙大宝 says:

    syntaxhighlighter

Leave a Reply

Your email address will not be published.