通过打擂台的思路找到当前最小值
import java.util.Arrays;
public class Test {
public static void main(String[] args){
int[] arr={9,5,2,7,3,8,1,6,4};
System.out.println(Arrays.toString(selectSort(arr)));
}
public static int[] selectSort(int[] arr){
for(int bound=0;bound<arr.length;bound++){
for(int cur=bound+1;cur<arr.length;cur++){
if(arr[cur]<arr[bound]){
swap(arr,cur,bound);
}
}
}
return arr;
}
public static void swap(int[] arr,int cur,int bound){
int tem=arr[cur];
arr[cur]=arr[bound];
arr[bound]=tem;
}
}