php实现冒泡原理
<?php
function bsort($array)
{
$count = count($array);
if($count == 0)
{
echo 0;
}
else if($count == 1)
{
echo $array;
}
else if($count > 1)
{
for($i=0;$i<$count;$i++)
{
for($j=$count-1;$j>$i;$j--)
{
if($array[j]<$array[j-1])
{
$temp = $array[j];
$array[j] = $array[j-1];
$array[j-1] = $temp;
}
}
}
return $array;
}
else
{
return false;
}
}
?>
$arr = array(2,1,56,87,57,34,24,34,78);
print (bsort($arr));
浙公网安备 33010602011771号