Sorting algorithms/Comb sort: Difference between revisions

added C
m (minor efficiency tweak for large gap sizes in J solution)
(added C)
Line 23:
'''end loop'''
'''end function'''
 
=={{header|C}}==
Implementation of Combsort11. Its efficiency can be improved by just switching to Insertion sort when the gap size becomes less than 10.
<lang c>void Combsort11(double a[], int nElements)
{
int i, j, gap, swapped = 1;
double temp;
 
gap = nElements;
while (gap > 1 || swapped == 1)
{
gap = gap * 10 / 13;
if (gap == 9 || gap == 10) gap = 11;
if (gap < 1) gap = 1;
swapped = 0;
for (i = 0, j = gap; j < nElements; i++, j++)
{
if (a[i] > a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
swapped = 1;
}
}
}
}</lang>
 
=={{header|C++}}==
179

edits