$arr = array(6, 3, 8, 2, 9, 1);
$c = count($arr)-1;
print_r($arr);
echo "冒泡<br>";
for ($i=0; $i < $c; $i++) {
for ($j=0; $j < $c-$i; $j++) {
if($arr[$j]>$arr[$j+1]){
$temp = $arr[$j];
$arr[$j] = $arr[$j+1];
$arr[$j+1] = $temp;
}
}
}
print_r($arr);
echo "选择<br>";
$arr = array(6, 3, 8, 2, 9, 1);
$c = count($arr);
for ($i=0; $i < $c-1; $i++) {
$minIndex = $i;
for ($j=$i+1; $j < $c; $j++) {
if($arr[$j]<$arr[$minIndex]) {
$minIndex = $j;
}
}
if($minIndex != $i) {
$temp = $arr[$i];
$arr[$i] = $arr[$minIndex];
$arr[$minIndex] = $temp;
}
}
print_r($arr);