Several sorting algorithm of Insertion Sort

Like similar insert cards

. 1  public  int [] insertSort ( int [] Array) {
 2      
. 3      // direct insertion sort
 4              // before the sort we need to find out an idea, a newly inserted data, the array is sorted after
 5              // small to large aligned, so we need to look forward from the back until you find more than we want to insert the digital still small
 6              // value. This time we need a variable j as an identifier 
. 7              for ( int I =. 1; I <be array.length; I ++ ) {
 . 8                  int TEMP = Array [I];
 . 9                  int j;
 10                  for (j =-I. 1; j> 0 =; J, ) {
 . 11                      // number will be greater than the rearward movement temp step 
12 is                      IF (Array [J]> temp) {
13 is                          Array [j +. 1] = Array [j]; // record the value of j is inserted to a position temp 
14                      } the else {
 15                          BREAK ;
 16                      }
 . 17                  }
 18 is                  Array [. 1 + j] = temp;
 . 19              }
 20 is              
21 is          
22 is      return Array;
 23 is }

 

Guess you like

Origin www.cnblogs.com/wangyufeiaichiyu/p/10944511.html