Sorting algorithms/Shell sort: Difference between revisions
Content added Content deleted
(Change Javascript header to the right text) |
No edit summary |
||
Line 893: | Line 893: | ||
output = -5 2 4 7 8 22 |
output = -5 2 4 7 8 22 |
||
</pre> |
</pre> |
||
=={{header|PHP}}== |
|||
<lang php> |
|||
function shellSort($arr) |
|||
{ |
|||
$inc = round(count($arr)/2); |
|||
while($inc > 0) |
|||
{ |
|||
for($i = $inc; $i < count($arr);$i++){ |
|||
$temp = $arr[$i]; |
|||
$j = $i; |
|||
while($j >= $inc && $arr[$j-$inc] > $temp) |
|||
{ |
|||
$arr[$j] = $arr[$j - $inc]; |
|||
$j -= $inc; |
|||
} |
|||
$arr[$j] = $temp; |
|||
} |
|||
$inc = round($inc/2.2); |
|||
} |
|||
return $arr; |
|||
} |
|||
</lang> |
|||
=={{header|PL/I}}== |
=={{header|PL/I}}== |