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

  • 相关阅读:
    连通最大子数组和(结对开发)
    第五周学习进度情况
    敏捷开发方法综述
    第四周学习进度情况
    环形数组最大子数组之和
    第四次程序(结对开发)
    第三周学习进度情况
    第三次程序—四则运算(结对开发)
    构建之法阅读笔记02
    按照Right-BICEP要求对实验二进行测试
  • 原文地址:https://www.cnblogs.com/darejoy/p/1745871.html
Copyright © 2011-2022 走看看