public class SelectSort {
public void sort(int a[]){
int N = a.length;
for (int i = 0; i < N-1; i++){
int min = i;
for (int j = i+1; j < N; j++){
if (a[j] < a[min]){
min = j;
}
if (min != i){
int temp = a[i];
a[i] = a[min];
a[min] = temp;
}
}
}
}
public static void main(String[] args){
int a[] = new int[]{4,3,5,2,1};
SelectSort x = new SelectSort();
x.sort(a);
for(int i: a){
System.out.println(i);
}
}
}
Java实现选择排序
最新推荐文章于 2024-01-26 15:09:30 发布