1 // Bubble Sorting 2 /* ******************AlgorithmDescription ********************** 3 1. traverse the unordered sequence and compare the number with the next one. If the number is larger than the next, exchange 4 2. Loop 1 until the length (called the number of workers, 5 Supplement 1: If there is no exchange in any of the switches, the sorting is successful. 6 Supplement 2: because the maximum value is placed at the end, the efficiency should be less than once. 7 **************************************** ******** */ 8 Void Sortbybubble ( Int Array [], Int Length) 9 { 10 Int Itemp; 11 // 2. Loop 1 until the length (called the number of workers, 12 For ( Int I = 0 ; I <length; I ++ ) 13 { 14 // 1. traverse the unordered sequence and compare the number with the next one. If the number is larger than the next, exchange 15 For ( Int J = 0 ; J <length- 1 -J; j ++) 16 { 17 // Compare the number with its next number. 18 If (Array [J]> array [J + 1 ]) // If this number is greater than the lower number 19 { 20 Itemp = Array [J]; 21 Array [J] = array [J + 1 ]; 22 Array [J + 1 ] = Itemp; 23 } 24 } 25 } 26 } 27 28 Void Print ( Int A [], Int Length) 29 { 30 For ( Int I = 0 ; I <length; I ++ ) 31 { 32 Printf ( " % D " , A [I]); 33 } 34 Printf ( " \ N " ); 35 } 36 37 Int Main () 38 { 39 Int A [ 10 ] = { 7 , 2 , 8 , 3 , 9 , 10 , 15 , 11 , 20 , 17 }; 40 Printf ( " Bubble Sorting: \ n " ); 41 Sortbybubble (, Sizeof ()/ Sizeof ( Int )); 42 Print (, Sizeof ()/ Sizeof ( Int )); 43 Return 0 ; 44 }