1.优点:简单,很稳定
2.缺点: 时间复杂度高,效率慢
3.口绝:两两相比小考前,外成循环-1,内成循环-1-i
5.代码`public class Dame2 {
public static void main(String[] args) {
Dame2 c = new Dame2();
c.aaa();
}
public void aaa(){
int a []= {12,32,21,31,4};
for (int i = 0; i < a.length-1; i++) {
for (int j = 0; j < a.length-1-i; j++) {
if (a[j+1]> a[j]) {
//交换位置
int b = a[j+1];
a[j+1]= a[j];
a[j]= b;
}
}
}
for (int i = 0; i < a.length; i++) {
System.out.print(a[i]+" ");
}
}
}
`