SelectSort 选择排序

//SelectSort (( O(n²)))
public class TestSelectSort { public int[] selectSortArray(int[] arr){
int min_index; for(int i = 0; i <arr.length - 1; i ++){
min_index = i;
for(int j = i + 1; j < arr.length; j ++){
if(arr[j] < min_index){
min_index = j;
}
if(min_index != i){
int temp;
temp = arr[i];
arr[i] = arr[min_index];
arr[min_index] = temp;
}
}
} return arr;
} public static void main(String[] args) {
int[] arr = {6,2,4,1,5,9};
TestSelectSort test = new TestSelectSort();
test.selectSortArray(arr); for(int i = 0 ; i < arr.length; i ++){
System.out.println(arr[i]);
}
} }

选择排序——每次最小/大排在相应的位置

上一篇:win7安装python3.6.1及scrapy


下一篇:hduacm 2888 ----二维rmq