zoukankan      html  css  js  c++  java
  • 查找

    1.   线性查找法    

          public class LinearSearch {
              public static int linearSearch(int[] list, int key){
                   for(int i = 0; i < list.length; i++){
                       if(key == list[i])
                       return i;
                  }
      
                   return -1;
              }

           }

    2.    二分查找法  

           public class BinarySearch {
              public static int binarySearch(int[] list, int key){
                 int low = 0;
                 int high = list.length - 1;
      
                 while(high >= low){
                        int mid = (high + low) / 2;
                        if(key < list[mid])
                              high = mid - 1;
                        else if(key == list[mid])
                              return mid;
                        else
                              low = mid + 1;
                   }
      
                   return -low -1;
               }

            }

  • 相关阅读:
    阅读笔记
    学习小记
    networkx学习笔记
    ORM查询简化
    redis等缓存
    redis相关缓存知识
    Centos7网络配置
    redis安装详细
    redis安装详细
    mobaxterm使用手册
  • 原文地址:https://www.cnblogs.com/jiangjh/p/2080078.html
Copyright © 2011-2022 走看看