/**
* 选择排序()
*/
public class SelectSort {
public static void main(String[] args) {
int []b={7,5,3,21,65,11};
selectsort(b);
}
public static void selectsort(int[] a){
int temp=0;
for(int i=0;i<a.length-1;i++){ //确定最小坐标
int minIndex=i;
for (int j=i+1;j<a.length;j++){
if(a[minIndex]>a[j]){
minIndex=j;
}
}
if(i!=minIndex){ //不等于则交换
temp=a[minIndex];
a[minIndex]=a[i];
a[i]=temp;
}
}
for (int value : a) {
System.out.println(value);
}
}
}
java选择排序
最新推荐文章于 2024-06-05 21:00:00 发布