zoukankan      html  css  js  c++  java
  • 二分法快速查找的递归算法

            private static int find(int[] arySource, int target, int start, int end)
            {
                if (start == end)
                {
                    if (arySource[start] == target)
                    {
                        return start;
                    }
                    else
                    {
                        return -1;
                    }
                }
                else if (start > end)
                {
                    return -1;
                }

                int curIndex = -1;
                curIndex = (start + end) / 2;

                int middleValue = arySource[curIndex];
                if (target == middleValue)
                {
                    return curIndex;
                }
                else if (target < middleValue)
                {
                    return find(arySource, target, start,  curIndex - 1 );
                }
                else
                {
                    return find(arySource, target,  curIndex + 1, end);
                }
            }

  • 相关阅读:
    网线 ------ 交叉线
    ubuntu ------ 网络 ifconfig 不显示IP地址
    STM32L011D4 ----- 低功耗
    List 集合 使用 remove 踩得坑
    Map 集合遍历的4种方法
    elasticsearch 集群详解
    谷歌浏览器添加插件时显示程序包无效:"CRX_HEADER_INVALID" 解决办法
    MySql数据库 优化
    MySql 索引
    Kibana 安装
  • 原文地址:https://www.cnblogs.com/darejoy/p/1745871.html
Copyright © 2011-2022 走看看