使用PHP描述冒泡排序,对象可以是一个数组,冒泡排序(数组排序):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
function bubble_sort($array){ $count = count($array); if ($count <= 0) return false; for($i=0; $i<$count; $i++){ for($j=$count-1; $j>$i; $j–){ if ($array[$j] < $array[$j-1]){ $tmp = $array[$j]; $array[$j] = $array[$j-1]; $array[$j-1] = $tmp; } } } return $array; } |
2022服务器特惠,真便宜!
①真便宜:阿里云服务器69元1年,203元3年(价格很低)
②代金券:2022阿里云代金券一键领取中
③腾讯云:2022腾讯云服务器秒杀特惠88元起
④免费提供技术支持:
原创文章,作者:PHP面试题,如若转载,请注明出处:http://www.phpmianshiti.com/suanfa/99/