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

    }

  • 相关阅读:
    leetcode第14题最长公共前缀
    什么是神经网络
    获取url "?" 后面的字符串
    第一天
    C#和.Ne学习第九天
    C#和.Ne学习第八天
    格式化输出
    C#和.Ne学习
    C#和.Ne学习第七天
    C#类型转换
  • 原文地址:https://www.cnblogs.com/jiangjh/p/2080084.html
Copyright © 2011-2022 走看看