java 冒泡排序

 public static void main(String[] args) throws ClassNotFoundException

   { 

        int[] a = {5,7,9,6,3,1};   change(a);      for(int i : a ){    System.out.print(i+"_");   

  }  

 }

  //从大到小

 public static void change(int[] a)

  {     

     for(int x = 0 ; x < a.length-1 ; x++){

          for(int i = 0; i < a.length-1-x; i++){  

             if(a[i]<a[i+1])

              {    

                int temp = a[i];      a[i] = a[i+1];      a[i+1] =temp;    

               }   

             }       

       }     

   }  

//从小到大

 public static void change1(int[] a)

  {      

    for(int x = 0 ; x < a.length-1 ; x++)

      {   

         for(int i = 0; i < a.length-1-x; i++)

          {    

             if(a[i] > a[i+1])

                {     

                     int temp = a[i+1];

                         a[i+1] = a[i];

                          a[i] =temp;  

                   }   

           }        

      }   

 }  

posted @ 2016-03-19 13:20  Melody丿丶Soul  阅读(147)  评论(0)    收藏  举报