Comb Sort
Comb sort is sorting algorithm and it is a variant of Bubble sort, the Comb Sort increases the gap used in comparisons and exchanges.
function CombSort(&$data, $count) {
$gap = $count;
$swaps = true;
while ($gap > 1 || $swaps)
{
$gap /= 1.247330950103979;
if ($gap < 1)
$gap = 1;
$i = 0;
$swaps = false;
while ($i + $gap < $count)
{
$igap = $i + $gap;
if ($data[$i] > $data[$igap])
{
$temp = $data[$i];
$data[$i] = $data[$igap];
$data[$igap] = $temp;
$swaps = true;
}
$i++;
}
}
}
Example
$data = array(-1, 25, -58964, 8547, -119, 0, 78596);
CombSort($data, 7);
Output
-58964
-119
-1
0
25
8547
78596