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

  • 相关阅读:
    四种常用正则表达式
    解读tomcat的server.xml文件
    存储过程与函数的区别
    Servlet如何处理一个请求?
    Oracle归档模式相关
    常用几个Struts2标签
    Js中比较时间大小
    传值出现中文乱码问题
    JAVA常用转义符
    HDU 5967(LCT)
  • 原文地址:https://www.cnblogs.com/darejoy/p/1745871.html
Copyright © 2011-2022 走看看