# Include <iostream>
Void swap (Int & A, Int & B ){
Int temp;
Temp =;
A = B;
B = temp;
}
/* Bubble sort
Basic Idea: first bubble to get a record with the smallest keyword, and second to get the second small value... for each record: the key words of the two adjacent records, if the reverse order is exchanged until there is no reverse order.
Features: time efficiency, a total of N-1 trip bubbles, a trip to the table of J records bubble needs to J-1 keyword comparison, space efficiency: Only one auxiliary unit (temporary variable)
*/
Void bubblesort (INT array [], int Len ){
Int I, J;
For (I = 0; I <len-1; I ++) {// I: 0 ~ Len-1 (I ++)
For (j = len-1; j> I; j --) {// J: len-1 ~ > I (j --) Minimum bubble
If (array [J-1]> array [J]) {
Swap (array [J], array [J-1]);
}
}
}
}
Int main (INT argc, const char * argv [])
{
Int I;
Int A [] = };
Int Len = sizeof (a)/sizeof (A [0]);
// Bubble sort
Bubblesort (A, Len );
For (I = 0; I <Len; I ++ ){
Printf ("% d", a [I]);
}
Printf ("\ n ");
Return0;
}
In-depth analysis of sorting algorithms-Bubble Sorting