标签:排序 sort ble str 冒泡 bubble i++ function 记录
思路: 两两比较相邻记录的关键字,将较小或较大的数逐步升上去
复杂度: O(n^2)
function bubbleSort($num){
for($i = 0; $i < count($num); $i++){
for($j = 0; $j < $n - $i - 1; $j++){
if($num[$j] > $num[$j+1]){
$num[$j+1] ^= $num[$j];
$num[$j] ^= $num[$j+1];
$num[$j+1] ^= $num[$j];
}
}
}
return $num;
}
标签:排序 sort ble str 冒泡 bubble i++ function 记录
原文地址:https://www.cnblogs.com/onlycat/p/10391326.html