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.
public static void CombSort(ref int[] data)
{
double gap = data.Length;
bool swaps = true;
while (gap > 1 || swaps)
{
gap /= 1.247330950103979;
if (gap < 1)
gap = 1;
int i = 0;
swaps = false;
while (i + gap < data.Length)
{
int igap = i + (int)gap;
if (data[i] > data[igap])
{
int temp = data[i];
data[i] = data[igap];
data[igap] = temp;
swaps = true;
}
++i;
}
}
}
Example
int[] data = new int[] { -1, 25, -58964, 8547, -119, 0, 78596 };
CombSort(ref data);
Output
-58964
-119
-1
0
25
8547
78596