public static void selectionSort(Comparable []data){
int intLength = data.length;
for(int i=0;i<intLength-1;i++){
int minIndex = i;
//Find smallest name
for(int j=i+1;j<intLength;j++){
Comparable a = data[j];
Comparable b = data[minIndex];
if(a.compareTo(b)<0){
minIndex = j;
}
}
//Swap data if necessary
if(minIndex!=i){
Comparable temp = data[i];
data[i] = data[minIndex];
data[minIndex] = temp;
}
}
}
public static void main(String []args){
Comparable []c={4,9,23,1,45,27,5,2};
selectionSort(c);
for(int i=0;i<c.length;i++){
System.out.println("选择排序:"+c[i]);
}
}
}
本文出自 “唐大老师” 博客,请务必保留此出处http://tscjsj.blog.51cto.com/412451/84582