Sesing the Data Structures & Algorithms in Java

According the Pearl in Programming ,the first correct  dicotomy search  algorithms is coded at 1966 thouth the algorithms is absent at 1946.Believe or not,but i think the followed code is right.
    
    public void dictomySearch(int[] arrays,int element,int begin,int end){
           if  (arrays[begin] == element) return begin;
          if  (arrays[end]   == element)  return end;
          if  (begin<=end) return -1;
          int mid = (begin+end)/2;
         if (arrays[mid]<element)
            return dictomySearch(arrays,element,mid+1,end-1);
         else if (arrays[mid]>element)
            return dictomySearch(arrays,element,begin+1,mid-1);
        else return mid;
    }

 
阅读更多
文章标签: arrays search java
想对作者说点什么? 我来说一句

Data structures and algorithms in java 6th

2015年01月15日 9.4MB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭