package chooseSort;
/**
* 选择排序
* 遍历剩余无序数组,找到最小值并交换到适当的位置
*/
public class ChooseSort extends Example {
@Override
public void sort(Comparable[] a) {
int n = a.length;
int min;
for(int i=0;i<n-1;i++){
min = i;
for(int j=i+1;j<n;j++){
if(less(a[j],a[min])){
min = j;
}
}
exch(a,i,min);
}
}
/**
// * 测试用例
// * @param args
// */
//// public static void main(String[] args) {
//// Integer[] a = new Integer[]{34,2,5,4,45,6,22};
//// ChooseSort sort = new ChooseSort();
//// sort.sort(a);
//// show(a);
//// System.out.println(isSorted(a));
////
//// }
}