java 选择排序
java selectionSort
public class SelectionSort {
public static void main(String[] args) {
int[] arr = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
selectionSort(arr);
System.out.println(Arrays.toString(arr));
}
public static void selectionSort(int[] arr) {
for (int j = 0; j < arr.length; j++) {
int minIndex = j;
for (int i = j + 1; i < arr.length; i++) {
if (arr[i] < arr[minIndex]) {
minIndex = i;
}
}
int temp = arr[j];
arr[j] = arr[minIndex];
arr[minIndex] = temp;
}
}
}