美文网首页
PHP实现:插入排序

PHP实现:插入排序

作者: JennyGump | 来源:发表于2017-01-04 00:18 被阅读0次
function insertion_sort(&$list)
{
    for ($i=1; $i < sizeof($list); $i++) {
        $temp = $list[$i];
        $j= $i - 1;
        for (; $j >= 0 && $list[$j] > $temp ; $j--) {
                # 需要插入 当前位置后移
                $list[$j+1] = $list[$j];
            }
            $list[$j+1] = $temp;
        }
}

相关文章

网友评论

      本文标题:PHP实现:插入排序

      本文链接:https://www.haomeiwen.com/subject/hbxovttx.html