Void Bubble (Char * Item, Int Count)
{
Register Int A, B;
Register char t;
For (a = 1; count; a)
FOR (B = count-1; b> = a; - b) {
// a = 1! Because B> = A, so B == a B-1 should be> = 0 is A-1> = 0, A> = 1
// b = count-1! COUNT is a number, the subscript is from 0 ~ count-1
IF (item [b-1]> item [b]) {
T = item [b-1]; item [b-1] = item [b]; item [b] = T;
}
}
}
Regardless of the initial situation,
Bubble sorted external circulation N-1 internal circulation N / 2, obtained (N ^ 2-N) / 2
low efficiency!
Void Shaker (Char * Items, Int Count)
{
Register int A;
Int Exchange;
CHAR T;
INT n = 1;
Do {
Exchange = 0;
For (a = count-n a> n-1-a)
IF (item [a-1]> item [a]) {
T = item [A-1]; item [a-1] = item [a]; item [a] = T;
EXCHANGE = 1;
} // Move the min size forward
FOR (a = n a IF (item [a-1]> item [a]) { T = item [A-1]; item [a-1] = item [a]; item [a] = T; EXCHANGE = 1; } // Maximum number of moves N; WHILE (Exchange); }