选择排序_Java

来源:互联网 发布:淘宝怎么创建子账号 编辑:程序博客网 时间:2024/06/16 19:40
public class Sort001 {
public static void selectSort(int [] a){
int temp=0;
int flag=0;
for(int i=0;i<a.length;i++){
temp=a[i];
flag=i;
for(int j=i+1;j<a.length;j++){
if(temp>a[j]){
temp=a[j];
flag=j;
}
}
if(flag!=i){
a[flag]=a[i];
a[i]=temp;
}
}
}
public static void main(String [] args){
int [] a={38,65,97,76,13,27,49};
selectSort(a);
for(int i=0;i<a.length;i++){
System.out.print(a[i]+" ");
}
System.out.println("\n");
}
}
0 0
原创粉丝点击