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

  • 相关阅读:
    Study Plan The TwentySecond Day
    Study Plan The Nineteenth Day
    Study Plan The TwentySeventh Day
    Study Plan The Twentieth Day
    Study Plan The TwentyFirst Day
    python实现进程的三种方式及其区别
    yum makecache
    JSONPath 表达式的使用
    oracle执行cmd的实现方法
    php daodb插入、更新与删除数据
  • 原文地址:https://www.cnblogs.com/darejoy/p/1745871.html
Copyright © 2011-2022 走看看