标签:++ bsp 退出 php版本 index 输出 循环 版本 for
function InsertSort(array $container)
{
$count = count($container);
for ($i = 1; $i < $count; $i++){
$temp = $container[$i];
$j = $i - 1;
// Init
while ($container[$j] > $temp){
$container[$j+1] = $container[$j];
$container[$j] = $temp;
$j--;
print_r($container);
if ($j < 0) break;
}
}
return $container;
}
print_r(InsertSort([3, 12, 42, 1, 24, 5, 346, 7]));
打印出i=3时输出的$container
Array
(
[0] => 3
[1] => 12
[2] => 1
[3] => 42
[4] => 24
[5] => 5
[6] => 346
[7] => 7
)
Array
(
[0] => 3
[1] => 1
[2] => 12
[3] => 42
[4] => 24
[5] => 5
[6] => 346
[7] => 7
)
Array
(
[0] => 1
[1] => 3
[2] => 12
[3] => 42
[4] => 24
[5] => 5
[6] => 346
[7] => 7
)
Array
(
[0] => 3
[1] => 12
[2] => 1
[3] => 42
[4] => 24
[5] => 5
[6] => 346
[7] => 7
)
Array
(
[0] => 3
[1] => 1
[2] => 12
[3] => 42
[4] => 24
[5] => 5
[6] => 346
[7] => 7
)
Array
(
[0] => 1
[1] => 3
[2] => 12
[3] => 42
[4] => 24
[5] => 5
[6] => 346
[7] => 7
)
Array
(
[0] => 1
[1] => 3
[2] => 12
[3] => 42
[4] => 24
[5] => 5
[6] => 346
[7] => 7
)
标签:++ bsp 退出 php版本 index 输出 循环 版本 for
原文地址:http://www.cnblogs.com/xcvv/p/7779191.html