PHP 算法 插入排序

function InsertSort(array $container)
{
$count = count($container);
for ($i = 1; $i < $count; $i++){
$temp = $container[$i];
$j = $i - 1;
while($j >= 0 && $container[$j] > $temp){
$container[$j+1] = $container[$j];
$j--;
}
if($i != $j+1)
$container[$j+1] = $temp;
}
return $container;
}

引用自 https://github.com/PuShaoWei/arithmetic-php,算法时间复杂度为O(n^2),只适用于小部分数据排序

原文地址:https://www.cnblogs.com/hubudong/p/9816303.html