排序

1.     选择排序     

 public class slectionSort {
     public static void slectionsort(double[] list){
           for(int i = list.length - 1; i >= 1; i--){
               double currentMax = list[0];
               int currentMaxIndex = 0;
  
               for(int j = 1; j <= i; j++){
                   if(currentMax < list[j]){
                       currentMax = list[j];
                       currentMaxIndex = j;
                     }
                }
     
               if(currentMaxIndex != i){
               list[currentMaxIndex] = list[i];
               list[i] = currentMax;
               }
           }
  
 }

}

2.  插入排序

public class InsertionSort {
 public static void insertionSort(double[] list){
  for(int i = 1; i < list.length; i++){
   
   double currentElement = list[i];
   int k;
   
   for(k = i - 1; k >= 0 && list[k] > currentElement; k--)
    list[k + 1] = currentElement;
  }
 }

}

原文地址:https://www.cnblogs.com/jiangjh/p/2080084.html