package sort;排序
public class Sort2 {
public static void main(String[] args) {
int[] a = { 2, 54, 23, 57, 72, 3, 46, 7, 8, 20, 324, 32, 1 };
SelectSort(a);
for (int i = 0; i < a.length; i++) {
System.out.print(a[i] + " ");
}
}class
/*
* 選擇排序(從小到大)
*/
public static void SelectSort(int a[]) {
for (int i = 0; i < a.length - 1; i++) {
int temp = i;
for (int j = i + 1; j < a.length; j++) {
if (a[i] > a[j]) {
temp = j;
}
swap(a, i, temp);
}
}
}sort
private static void swap(int[] a, int i, int j) {
int temp = a[j];
a[j] = a[i];
a[i] = temp;
}
}static