选择排序

2011-03-03  李卓华 

public class SelectSort {
public static void main(String [] args){
int [] a = {1,52,3,21,541,122,321};
for(int i = 0; i < a.length; i++){
int idx = i;
for(int j = i+1; j < a.length ; j++){
if ( a[idx] > a[j]){
idx = j;
}
}
if(idx > i){
a[i] = a[i] + a[idx];
a[idx] = a[i] - a[idx];
a[i] = a[i] - a[idx];
}
}
for(int c: a){
System.out.println(c);
}
}
}

288°/2882 人阅读/0 条评论 发表评论

登录 后发表评论