Sesing the Data Structures & Algorithms in Java

博客提到首个正确的二分查找算法于1966年编码完成,虽该算法在1946年就已存在。还给出了Java语言实现的二分查找算法代码,通过递归方式在数组中查找元素。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值