基本思想:在要排序的一组数中,对当前还未排好序范围内的全部数,自上而下对相邻的两个数一次进行比较和调整,让较大的数往下沉,较小的网上冒:当两相邻的数比较 后,发现他们的排序与排序要求相反时,就将他们互换。
public class bubbleSort{
int a[]={};
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]){
int temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
for(int i=0;a<a.length;i++){
System.out.println(a[i]);
}
}