java冒泡排序和选择排序

来源:互联网 发布:高中英语语法视频 知乎 编辑:程序博客网 时间:2024/06/01 21:38
int[] a={1,2,11,11,5,11,7,8,9,0};
int temp=0;
//冒泡排序
// for(int i=0;i<9;i++){
// for(int j=0;j<9-i;j++){
// if(a[j+1]>a[j]){
// temp=a[j];
// a[j]=a[j+1];
// a[j+1]=temp;
// count ++;
// }
// }
// }
//
//选择排序
for(int i=0;i<9;i++){
temp=a[i];
for(int j=i;j<9;j++){
if(a[j]>temp){
temp=a[j];
a[j]=a[i];
a[i]=temp;
}
}
}

for(int k=0;k<a.length;k++){

System.out.println(a[k]);
}

}
0 0