The most detailed history of bubble sort algorithm C language

Without consent, please do not reprint.

. 1  void bubbing () {
 2      int init_arr [ 10 ] = { . 1 , . 5 , . 9 , . 8 , . 7 , . 6 , . 7 , 99 , . 8 , 10 }; // DEFINE the init The Array
 . 3      // going to exinternal The Loop, from 0 to Loop Start 
. 4      int tmp;
 . 5      int len = the sizeof (init_arr) / . 4 ; // get the length of the array, since each type int c language total of four bytes, the dividing. 4 
. 6      for (int I = 0 ; I <len; I ++) { // The outer loop starts comparing the first number, each one down, one can obtain the maximum value, then the final surface in an array. 
. 7          for ( int J = 0 ; J <len-I- . 1 ; J ++) { // J is also the initial value of 0, but the traverse len-i-1 to time to time is no longer traversed, because len-j- the latter value is the value of a good sequence has been discharged. 
. 8              IF (init_arr [J + . 1 ] <init_arr [J]) { // begin to judge, each one adjacent two values are determined by the size, the larger into the back. 
. 9                  int T = init_arr [J];
 10                  init_arr [J] = init_arr [J + . 1 ];
 . 11                  init_arr [J + . 1 ] = T;
 12 is             }
 13 is  
14          } // the printf ( "% D", init_arr [I]); 
15      }
 16      for ( int K = 0 ; K <len . 1 ; K ++) { // print the sorted array 
. 17          the printf ( " D% \ n- " , init_arr [K]);
 18 is      }
 . 19  
20 is }

 

Guess you like

Origin www.cnblogs.com/szj666/p/11865052.html