`
erntoo
  • 浏览: 27253 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论
  • erntoo: 修改somaxconn该内核参数默认值一般是128,对于负载很 ...
    rpm

PHP算法-冒泡排序

    博客分类:
  • PHP
阅读更多
function bubble_sort($arr)
{
    $count = count($arr);
    if ($count <= 1) {
        return $arr;
    }
    $times = $count - 1;
    for ($i = 0; $i < $times; $i ++) {
        for ($j = 0; $j < $count - $i - 1; $j ++) { // 第一遍排序最后一个已经是最大值 故$count-$i
            if ($arr[$j] > $arr[$j + 1]) {
                $tmp = $arr[$j];
                $arr[$j] = $arr[$j + 1];
                $arr[$j + 1] = $tmp;
            }
        }
    }
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics