Bubble Sort

Bubble sort (a.k.a Sinking Sort and Comparison Sort) is a sorting algorithm that works by repeatedly swapping and adjacent elements if they are in wrong order.



									void BubbleSort(int* data, int count) {
	for (int i = 1; i < count; ++i)
	{
		for (int j = 0; j < count - i; ++j)
		{
			if (data[j] > data[j + 1])
			{
				data[j] ^= data[j + 1];
				data[j + 1] ^= data[j];
				data[j] ^= data[j + 1];
			}
		}
	}
}
								


Example

									int data[] = { -1, 25, -58964, 8547, -119, 0, 78596 };
BubbleSort(data, 7);
								


Output

									-58964
-119
-1
0
25
8547
78596