<?php
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
function ShellSort($data, $L)
{
$time_start = microtime_float();
for ($i = floor($L / 2); $i > 0; $i = floor($i / 2)) {
for ($j = $i; $j < $L; $j++) {
for ($k = $j; $k >= $i && $data[$k] < $data[$k - 1]; $k -= $i) {
list($data[$k], $data[$k - 1]) = [$data[$k - 1], $data[$k]];
}
}
}
$time_end = microtime_float();
echo "ShellSort - Time:" . ($time_end - $time_start) . "s" . "<br/>";
return $data;
}
function main()
{
$number = [];
for ($i = 0; $i < 10000; $i++) {
$number[] = rand(0, 1000000000);
}
ShellSort($number, count($number));
}
main();