Home > php教程 > PHP源码 > body text

PHP简单的冒泡排序法(。•ˇ‸ˇ•。)

PHP中文网
Release: 2016-05-22 18:24:59
Original
977 people have browsed it

php代码

<?php
$b = [5,2,7,3,1,6,8,0];
// $b = [8,7,6,5,4,3,2,1,0];#直观地看出需要复循环几遍
$n = count($b);

for($s = 0;$s < $n;$s++){

	for($i = 0;$i $b[$i+1]) {	#升序排序

			$tmp = $b[$i+1];

			$b[$i+1] = $b[$i];

			$b[$i] = $tmp;
		}
	}
}
print_r($b);
Copy after login

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template