Selection sort, to find the most value and traverse

1  //     Method to find the minimum value of the array 
2      public  static  void getMin ( int [] arrArg) {
 . 3          int min = 0 ;
 . 4          for ( int I = 0; I <arrArg.length; I ++ ) {
 . 5              IF (arrArg [I ] < arrArg [min]) {
 . 6                  min = I;
 . 7              }
 . 8          }
 . 9          System.out.println (arrArg [min]);
 10      }
 . 11  //     selection sort ascending method 
12 is      public  static  void ARRS (int []arrArg) {
13         for (int i = 0; i < arrArg.length; i++) {
14             for (int j = i+1; j < arrArg.length; j++) {
15                 if (arrArg[i]>arrArg[j]) {
16                     int max = arrArg[i];
17                     arrArg[i] = arrArg[j];
18                     arrArg[j] = max;
19                 }
20             }
21         }
22     }
23 //    遍历数组的方法
24     public static void teap(int [] arr) {
25         for (int i = 0; i < arr.length; i++) {
26             if (i<arr.length-1) {
27                 System.out.print(arr[i]+", ");
28             }else {
29                 System.out.print(arr[i]);
30                 System.out.println();
31             }
32         }
33     }

Experience: the so-called selection sort is to use the number to compare the subject at A and other locations, such as minimum and then find the place on the A, then A number of the current location to another location and number ... and so on .

Guess you like

Origin www.cnblogs.com/jijijijibeibeibei/p/12018505.html