首页 > 代码库 > 用php做了下冒泡排序

用php做了下冒泡排序

大学没好好读书,那会没怎么明白冒泡排序是这么回事

早上睡到九点多起来,就在房间看书、听歌,下午吃完饭做了下冒泡排序,现在把代码贡献如下:

 

<?php/** * Created by PhpStorm. * User: Administrator * Date: 2016/8/27 0027 * Time: 12:24 * 冒泡排序 */header(‘Content-type: text/html; charset=utf-8‘);$number=array("10","2","9","1","5","8","4","7","3","6");for( $i=0;$i<count($number);$i++){    echo $number[$i]. " ";}echo "<br/>";echo  "冒泡后的顺序";$temp=0;for($n=0;$n<count($number);$n++){    for($m=0;$m<count($number);$m++){        if($number[$n]>$number[$m]){            $temp=$number[$n];            $number[$n]=$number[$m];            $number[$m]=$temp;        }    }}for( $N=0;$N<count($number);$N++){    echo $number[$N]. " ";}echo "<br/>";die();?>

其实还可以改良的,节省时间空间,有时间我拿来改改。

用php做了下冒泡排序