无风无影

   ::  :: 新随笔  ::  ::  :: 管理

冒泡排序

 1 public class BubbleSort {
 2 
 3     public static void main(String[] args) {
 4         int [] array={88,11,2,1,19,88,77,66,99,88};
 5         bubbleSort(array);
 6         for(int i=0;i<array.length;i++){
 7             System.out.print(array[i]+" ");
 8         }
 9     }
10     private static void bubbleSort(int[] array){
11         for(int i=0;i<array.length;i++){
12             for(int j=1;j<array.length-i;j++){
13                 if(array[j]<array[j-1]){
14                     int value=array[j-1];
15                     array[j-1]=array[j];
16                     array[j]=value;
17                 }
18             }
19         }
20     }
21 }
View Code

 

posted on 2018-05-28 18:40  NWNS-无风无影  阅读(122)  评论(0)    收藏  举报