笔记-选择排序算法
1 public class Check { 2 //选择排序算法 3 public void xuanze(int[] array){ 4 for(int i = 0; i< array.length; i++){ 5 for(int j = i+1; j< array.length; j++){ 6 if(array[i] > array[j]) 7 { 8 int temp = array[i]; 9 array[i] = array[j]; 10 array[j] = temp; 11 } 12 } 13 } 14 } 15 16 17 public void dayin(int[] array){ 18 for(int i = 0; i< array.length; i++) 19 { 20 System.out.print(array[i]+" "); 21 } 22 } 23 24 25 public static void main(String[] args){ 26 27 int[] A={2, 4, 1, 7, 5, 8, 9, 6, 3}; 28 Check ck =new Check(); 29 ck.dayin(A); 30 ck.xuanze(A); 31 System.out.println(); 32 ck.dayin(A); 33 } 34 }
运行结果