当前位置:网站首页>binarySearch基础二分查找
binarySearch基础二分查找
2022-07-25 19:25:00 【_Doris___】



ac实现代码:
Position BinarySearch( List L, ElementType X )
{
int left=1,right=L->Last,mid=(left+right)/2;
while(left<=right)
{
if(L->Data[mid]>X)
{
right=mid-1;
}
else if(L->Data[mid]<X)
{
left=mid+1;
}
else if(L->Data[mid]==X)
{
return mid;
}
mid=(left+right)/2;
}
return NotFound;
}细节:
left<=right不能是小于号,否则偶数个,在正中间找到了之后,无法进入循环,漏情况。
边栏推荐
- 微信小程序 28 热搜榜的完善①
- JS basic type reference type deep / shallow clone copy
- [reading notes] deep learning Chapter 1: Introduction
- Eve - 0day Threat Intelligence
- 基于FPGA的1080P 60Hz BT1120接口调试过程记录
- 某公司网络设计与规划
- Monitor MySQL based on MySQL exporter
- telnet安装以及telnet(密码正确)无法登录!
- 基于PHP的中非南南合作信息交流平台网站建设
- The second "future Cup" knowledge map championship was officially launched
猜你喜欢

小程序毕设作品之微信校园维修报修小程序毕业设计成品(8)毕业设计论文模板

“未来杯”第二届知识图谱锦标赛正式启动

Clip can also do segmentation tasks? The University of Gottingen proposed a model clipseg that uses text and image prompt and can do three segmentation tasks at the same time, squeezing out the clip a

Network packet multi-layer transmission demonstration

小程序毕设作品之微信校园维修报修小程序毕业设计成品(7)中期检查报告

微信小程序 26 播放音乐页的完善②

聊聊接口性能优化的11个小技巧

Fruit chain "siege": it's a journey of sweetness and bitterness next to apples

Pymoo learning (6): termination conditions

微信小程序 29 热搜榜的完善②
随机推荐
Empire CMS whole station | mobile number /qq lianghao mall source code | suitable for mobile terminal
C# 合并集合
iMeta | Sangerbox: 交互式整合临床生信分析平台
Pymoo learning (6): termination conditions
GBASE 8s UDR内存管理_01_mi_alloc
SQL Server 2019 installation tutorial
【小程序开发】宿主环境详解
阿里云免费SSL证书申请详细流程
Sccm2012r2 network deployment reinstallation system
Wechat campus maintenance application applet graduation design finished product of applet completion work (3) background function
由一个蓝桥杯基础题报时助手而引出的常见误区
新瓶装老酒--近期APT32(海莲花)组织攻击活动样本分析
【HDLBits 刷题】Verilog Language(3)Modules: Hierarchy 部分
阿姆利塔工程学院|用于情感分析的方面术语提取中优化采样的强化主动学习方法
FPGA based 1080p 60Hz bt1120 interface debugging process record
网上商城系统MySql数据库设计项目实战
kubernetes RBAC
Eve - 0day Threat Intelligence
Alibaba cloud free SSL certificate application detailed process
Based on easycv to reproduce Detr and dab-detr, the correct opening method of object query