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.



									/*****Please include following header files*****/
// stdbool.h
/***********************************************/

void CombSort(int* data, int count) {
	double gap = count;
	bool swaps = true;

	while (gap > 1 || swaps)
	{
		gap /= 1.247330950103979;

		if (gap < 1)
			gap = 1;

		int i = 0;
		swaps = false;

		while (i + gap < count)
		{
			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[] = { -1, 25, -58964, 8547, -119, 0, 78596 };
CombSort(data, 7);
								


Output

									-58964
-119
-1
0
25
8547
78596