You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
575 B
PHP
29 lines
575 B
PHP
<?php
|
|
|
|
function shell_Sort($my_array)
|
|
{
|
|
$x = round(count($my_array)/2);
|
|
while($x > 0)
|
|
{
|
|
for($i = $x; $i < count($my_array);$i++){
|
|
$temp = $my_array[$i];
|
|
$j = $i;
|
|
while($j >= $x && $my_array[$j-$x] > $temp)
|
|
{
|
|
$my_array[$j] = $my_array[$j - $x];
|
|
$j -= $x;
|
|
}
|
|
$my_array[$j] = $temp;
|
|
}
|
|
$x = round($x/2.2);
|
|
}
|
|
return $my_array;
|
|
}
|
|
|
|
$test_array = array(3, 0, 2, 5, -1, 4, 1);
|
|
echo "Original Array :\n";
|
|
echo implode(', ',$test_array );
|
|
echo "\nSorted Array\n:";
|
|
echo implode(', ',shell_Sort($test_array)). PHP_EOL;
|
|
|
|
?>
|