一、冒泡

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 PHP

2 Replies

发表评论

电子邮件地址不会被公开。