/*
* czl 选择排序
*/
public class selectSort{
public static void main(String[] args){
int[] a = {1,5,3,2,1};
int minIndex ;
int temp;
for(int i=0;i<a.length;i++){
minIndex=i;
for(int j=i+1;j<a.length;j++){
if(a[j]<a[minIndex]){
minIndex= j;
}
}
if(minIndex!=i){
temp=a[i];
a[i]=a[minIndex];
a[minIndex]=temp;
}
}
for(int k=0;k<a.length;k++)
System.out.println(a[k]);
}
}
选择排序
最新推荐文章于 2025-05-03 10:56:02 发布