自己整理的排序算法之(1) 选择排序

 1 //选择排序
 2 package sort;
 3 
 4 public class SelectionSort {
 5     public static void SelectionSort(double[] list){
 6         for(int i=0;i<list.length-1 ;i++){
 7             double currentMin = list[i];
 8             int currentMinIndex = i;
 9             
10             for(int k=i+1 ;k<list.length ; k++){
11                 if(currentMin>list[k]){
12                     currentMin = list[k];
13                     currentMinIndex = k;    
14                 }    
15             }
16             
17             if(currentMinIndex != i){
18                 
19                 list[currentMinIndex] = list[i];
20                 list[i] =currentMin; 
21             }
22         }
23     }
24     
25     public static void main(String[] args){
26         double[] list ={5.2 , 1.4 , 6.3,  2.3  ,4.6};
27         SelectionSort(list);
28         for(int i =0;i<list.length;i++){
29             System.out.print(list[i]+" ");
30         }
31     }
32 }

 

posted @ 2016-09-07 21:54  小竹子kisty  阅读(198)  评论(0编辑  收藏  举报