zoukankan      html  css  js  c++  java
  • 排序

    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;
      }
     }

    }

  • 相关阅读:
    作业三3
    作业三2(改过)
    第一章
    实验2
    第三章
    例2-11
    例2-10
    例2-8
    例2-9
    例2-7
  • 原文地址:https://www.cnblogs.com/jiangjh/p/2080084.html
Copyright © 2011-2022 走看看