/**
* 选择排序 选择排序的思路是:是从第一个元素和后面的元素进行比较,获取到最小的元素,进行比较交换
* 不稳定排序
*/
public class SelectSort {
public void selectSort(int[] array) {
for (int i = 0; i < array.length; i++) {
int temp = array[i];
for (int j = i + 1; j < array.length; j++) {
if (temp > array[j]) {// 选出最小元素,交换
array[i] = array[j];
array[j] = temp;
temp = array[i];
}
}
}
}
public static void main(String[] args) {
int[] a = { 10, 8, 3, 9, 47, 12, 14, 8, 5, 0, 2 };
SelectSort selectSort = new SelectSort();
selectSort.selectSort(a);
PrintUtil.printArray(a);
}
}