1 public class BubbleSort(){ 2 int [] bubble(int a[]){ 3 int len = a.length; 4 for(int i = 0;i<len-1;i++){ //len-1为外层比较的次数,为总数减一 5 int temp = 0; 6 for(int j = 0;j<len-1-i;j++){ 7 if(a[j]>a[j+1]){ 8 temp = a[j]; 9 a[j] = a[j+1]; 10 a[j+1] = temp; 11 } 12 } 13 } 14 return a; 15 } 16 }
好了!
原文:https://www.cnblogs.com/WcxyBlog/p/11593436.html