交换排序---冒泡排序

 1     //冒泡排序
 2     /**
 3      * 5,8,3,15,14,68,17
 4      * 
 5      * @param arr
 6      */
 7     public static void bubbleSort(int[] arr){
 8         //控制比较多少轮
 9         for(int i=0;i<arr.length-1;i++){
10             for(int j=0;j<arr.length-1-i;j++){
11                 if(arr[j]>arr[j+1]){
12                     int temp=arr[j];
13                     arr[j]=arr[j+1];
14                     arr[j+1]=temp;
15                 }
16             }
17         }
18     }

猜你喜欢

转载自www.cnblogs.com/axu521/p/9973832.html