//php中 <?php /*冒号排序开始*/ $num=array(90,70,50,30,20,0,10,40,60,80); $cnt=count($num); //print_r($cnt); for($i=0;$i<$cnt;$i++){ //print_r($i);0123456789 for($j=0;$j<$cnt-$i-1;$j++){ //print_r($j);012345678012345670123456012345012340123012010 if($num[$j]>$num[$j+1]){ $temp=$num[$j]; $num[$j]=$num[$j+1]; $num[$j+1]=$temp; } } } print_r($num); /*冒号排序结束*/ ?> //python def bub(bublist): listlength = len(bublist) while listlength > 0: for i in range(listlength - 1): if bublist[i] > bublist[i+1]: bublist[i]=bublist[i]+bublist[i+1]; bublist[i+1]=bublist[i]-bublist[i+1]; bublist[i]=bublist[i]-bublist[i+1]; listlength -= 1 print bublist if __name__=='__main__': bublist=[60,50,30,40,20,10]; bub(bublist);
冒号排序(php和python)
最新推荐文章于 2024-04-29 20:57:21 发布