标签:rgs 选择排序 public print sort select ++ ring int
for(i=0; i<N; i++)
public class SelectSort {
public static void main(String[] args) {
int [] arr = {49,38,65,97,76,13,27,49};
selectSort(arr,arr.length);
}
public static void selectSort(int [] arr,int n){
for (int i = 0; i < n - 1; i++) {
int index = i;
int j;
// 找出最小值得元素下标
for (j = i + 1; j < n; j++) {
if (arr[j] < arr[index]) {
index = j;
}
}
int tmp = arr[index];
arr[index] = arr[i];
arr[i] = tmp;
System.out.println(Arrays.toString(arr));
}
}
}
标签:rgs 选择排序 public print sort select ++ ring int
原文地址:https://www.cnblogs.com/wbyixx/p/12230012.html