package sort_algorithm;
/**
* 选择排序
*/
public class SelectSort {
public static void selectSort(int[] selectSource){
int temp;
for(int i=0;i<selectSource.length;i++){
int index=i;//查找最小值
for(int j=i;j<selectSource.length;j++){
if(selectSource[j]<selectSource[index])
index=j;
}
if(index!=i){
temp=selectSource[i];
selectSource[i]=selectSource[index];
selectSource[index]=temp;
}
}
}
public static void main(String[] args) {
int[] a={2,3,1,4,5};
SelectSort.selectSort(a);
for(int aa : a){
System.out.println(aa);
}
}
}