Sort Algorithms Algorithm -shell (exchange)

Analysis can look at the commented out, looking at the last three for loop

Package com.ebiz.sort; 

Import java.util.Arrays; 

/ ** 
 * @author YHJ 
 * @Create 2019-07-30 8:53 
 * Sort the shell - exchange 
 * / 
public  class Shell { 

    public  static  void main (String [] args) { 

        int [] ARR = {8,9,1,7,2,3,5,4,6 }; 
        the getResult (ARR); 
       // System.out.println (of Arrays.toString (ARR)) ; 

        // second packet 5/2 = 22 groups, each interval of the step 2 is two numbers,
         // number of group 5, the outer loop, a fourth group, a total of eight times
 //         for (int I = 2; I <arr.length; I ++) {
 //             // established to compare the number of step size
 //            for (int I = J-2; J> = 0; = J-2) {
 //                 IF (ARR [J]> ARR [J + 2]) {
 //                     int ARR TEMP = [J + 2];
 / /                     ARR [J + 2] = ARR [J];
 //                     ARR [J] = TEMP;
 //                 }
 //             }
 // 
//         }
 //         System.out.println (of Arrays.toString (ARR)); 

        / / 3rd packet 2/2 = 1 1 ,, each interval group number two steps is 1,
         @ a group number 10, the outer loop, a group 9, a total of 9
 //         for (int. 1 = I; I <arr.length; I ++) {
 //             // establish the number of steps to be compared
 //             for (int. 1-I = J; J> = 0; J-=. 1) {
//                 IF (ARR [J]> ARR [J +. 1]) {
 //                     int ARR TEMP = [J +. 1];
 //                     ARR [J +. 1] = ARR [J];
 //                     ARR [J] = TEMP;
 //                 }
 //             }
 // 
//         } 
        System.out.println (of Arrays.toString (ARR)); 

    } 

    public  static  void the getResult ( int [] ARR) {
 //         // first packet 10/2 = 55 groups, each interval of the step 5 two numbers,
 //         // a set of two numbers, the outer loop a group 1, a total of five times
 //         for (int I = 5; I < arr.length; I ++) {
 //             //Establishing the number of steps to be compared
 //             for (int. 5-I = J; J> = 0; J-=. 5) {
 //                 IF (ARR [J]> ARR [+ J. 5]) {
 //                     int ARR = TEMP [+ J. 5];
 //                     ARR [+ J. 5] = ARR [J];
 //                     ARR [J] = TEMP;
 //                 }
 //             }
 // 
//         } 

        // controlling the number of component 
        for ( int I = arr.length / 2; I> =. 1; I / = 2 ) {
             // the control of the number of each comparison 
            for ( int J = I; J <arr.length; J ++ ) {
                 // each compare and exchange
                for (int k= j-i; k >=0 ; k-=i) {
                    if (arr[k]>arr[k+i]){
                        int temp=arr[k+i];
                        arr[k+i]=arr[k];
                        arr[k]=temp;
                    }
                }

            }


        }


    }

}

To be perfect ...

Guess you like

Origin www.cnblogs.com/jiushixihuandaqingtian/p/11299220.html