implement bubble sort java

1  / * 
2  * Bubble Sort
 3  * how many times the outer control loop, the inner loop controls the number of each pass
 . 4   * / 
. 5  public  class Test08 {
 . 6      public  static  void main (String [] args) {
 . 7          int NUM [ ] = {1,9,2,8,4,7,6,5,3 };
 . 8          System.out.println ( "before sorting array is:" );
 . 9          for ( int SNUM: NUM) {
 10              the System .out.print (SNUM + "" );
 . 11          }
 12 is          for ( int I =. 1; I <num.length; I ++ ) {
 13 is              for (int j = 1; j < num.length-i; j++) {
14                 if (num[j]>num[j+1]) {
15                     int temp = num[j];
16                     num[j] = num[j+1];
17                     num[j+1] = temp;
18                 }
19             }
20         }
21         System.out.println();
22         System.out.println("排序后的数组为:");
23         for (int snum:num) {
24             System.out.print(snum+"");
25         }
26     }
27 }

https://www.cnblogs.com/shen-hua/p/5422676.html

Guess you like

Origin www.cnblogs.com/zhangzimuzjq/p/11453715.html