选择排序的思想:从最左边开始,依次和后面的所有元素进行比较,小的数往前移,每一趟比较完毕后,最小的数就出现在最前面。
package com.sxt.add;
import java.util.Arrays;
public class zhan {
public static void main(String[] args) {
int[] a = { 19, 2, 4, 1, 7 };
TI(a);
System.out.print(Arrays.toString(a));
}
public static void TI(int[] a) {
for (int i = 0; i < a.length - 1; i++) {
for (int j = i+1; j < a.length; j++) {
if (a[i]>a[j]) {
int t = a[j];
a[j] = a[i];
a[i] = t;
}
}
}
}
}