Closed igo9go closed 6 years ago
或者直接这样写就可以了
function bubbleSortV3(&$arr) : void
{
$newn = 0;
$c = count($arr);
for ($i = 0; $i < $c-1; $i++) {
$flag = true;
for ($j = 0; $j < $c-$i-1; $j ++) {
if ($arr[$j] > $arr[$j + 1]) {
list($arr[$j], $arr[$j + 1]) = array($arr[$j + 1], $arr[$j]);
}
}
}
}
你指的是 这种写法 ?
function bubuleSort(&$arr)
{
$length = count($arr);
for ($i = 0; $i < $length; $i++) {
for ($j = 0; $j < $length - $i -1; $j ++) {
if ($arr[$j + 1] > $arr[$j]) {
list($arr[$j + 1], $arr[$j]) = [$arr[$j], $arr[$j + 1]];
}
}
}
}
另外 你提交的PR的代码 我没看出来哪里有变化 ,貌似 只是替换了一下变量 @igo9go
bug fix