Like all comparison based sorting techniques Bubble Sort is based on comparing two keys and rearranging the associated data in order to place the keys in ascending or descending order.
Bubble Sort was one of the first sorting methods created. It is also the simplest. Bubble Sort was so named because as you repeatedly scan the array of records making comparisons the lower value keys gradually "bubble" to the start of the array.
/***************************************/ /* BubbleSort() */ /* */ /* Sort records on integer key using */ /* a bubble sort. */ /***************************************/ void BubbleSort(StructType DataArray[], int count) { int i, j; StructType temp; for(i=0; i<count; i++) { for(j=0; j<(count-i - 1); j++) { if(DataArray[j].key > DataArray[j+1].key) { temp = DataArray[j]; DataArray[j] = DataArray[j+1]; DataArray[j+1] = temp; } } } }