public class BubbleSort {
/**
* @param args
*/
public static void main(String[] args) {
int[] a = {10,5,2,3,345,67,90};//7
BubbleSort(a);
// 1. 10,5,3,345,67,90,2
//.
}
public static void BubbleSort(int a []){
int temp=0;
int count=0;
for (int i = 0; i < a.length-1 ; i++) {
for (int j = 0; j < a.length - i - 1; j++){
if (a[j]<a[j + 1]){ //把这里改成大于,就是升序了
temp = a[j];
a[j] = a[j + 1];
a[j+1] = temp;
}
}
++count;
System.out.println(" 循环次数" + count);
for(int k = 0;k< a.length;k++){
System.out.print(" " + a[k]);
}
}
// System.out.println(" 循环次数" + count);
// for(int i = 0;i< a.length;i++){
// System.out.print(" " + a[i]);
// }
}
}