Skip to content

Commit

Permalink
Merge pull request diptangsu#113 from AnupamaTK/patch-5
Browse files Browse the repository at this point in the history
Create ShellSort.php
  • Loading branch information
diptangsu authored Oct 30, 2019
2 parents 1de8689 + 5b6c64f commit e7b6ef5
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions ShellSort.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?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;
?>

0 comments on commit e7b6ef5

Please sign in to comment.