冒泡排序是最没有效率的排序,原因是 短视
/**
* Created by fupeng on 2017/1/20.
*/
public class bubble {
static void show(int [] a){
for(int i : a){
System.out.println(i);
}
}
static void exch(int [] a, int i, int j){
int t = a[i];
a[i] = a[j];
a[j] = t;
}
static void sort(int [] a){
for(int i=0 ; i<a.length -1 ; i++){
for(int j=0; j< a.length - i - 1; j++){
if(a[j+1] < a[j] )
exch(a, j+1, j);
}
}
}
public static void main(String[] args) {
int [] a = {2,3,4,1,5,9,8,6,7,0};
sort(a);
show(a);
}
}