选择排序
1 public class selectSort { 2 public static void selectSort() { 3 int a[] = {1, 54, 6, 3, 78, 34, 12, 45}; 4 int position = 0; 5 for(int i = 0; i < a.length; i++) { 6 int j = i + 1; 7 position = i; 8 int temp = a[i]; 9 for(; j < a.length; j++) { 10 if(a[j] < temp) { 11 temp = a[j]; 12 position = j; 13 } 14 } 15 a[position] = a[i]; 16 a[i] = temp; 17 } 18 for(int i = 0; i < a.length; i++) 19 System.out.println(a[i]); 20 } 21 public static void main(String[] args) { 22 selectSort(); 23 } 24 }