/** * 选择排序 * @Author: Mr.li * @Date: 2019/11/29 */ 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 length) { for (int i = 0; i < length - 1; i++) { int index = i; int j; //找出最小值的元素下标 for (j = i + 1; j < length; j++) { if (arr[j] < arr[index]) { index = j; } } int temp = arr[index]; arr[index] = arr[i]; arr[i] = temp; System.out.println(java.util.Arrays.toString(arr)); } } }