当前位置:网站首页>折半查找法
折半查找法
2022-06-23 03:32:00 【@风景邮递Yuan】
折半查找
折半查找依赖的是顺序表结构,简单点说就是数组。
• 二分查找针对的是有序数据。
• 数据量太小不适合二分查找。
• 数据量太大也不适合二分查找。
/* 折 半 查 找 */
int Binary_Search (int *a, int n, int key ){
int low , high , mid ;
/* 定 义 最 低 下 标 为 记 录 首 位 */
low = 1;
/* 定 义 最 高 下 标 为 记 录 末 位 */
high = n;
while (low <= high ) {
/* 折 半 */
mid = ( low + high ) / 2;
/* 若 查 找 值 比 中 值 小 */
if (key < a[mid ])
/* 最 高 下 标 调 整 到 中 位 下 标 小 一 位 */
high = mid - 1;
/* 若 查 找 值 比 中 值 大 */
else if (key > a[mid ])
/* 最 低 下 标 调 整 到 中 位 下 标 大 一 位 */
low = mid + 1;
else
/* 若 相 等 则 说 明 mid 即 为 查 找 到 的 位 置 */
return mid ;
}
return 0;
}边栏推荐
- What is the difference between comparator and comparable?
- The compatibility of remotefx schemes is related to multiple factors
- Heavyweight review: strategies for reliable fMRI measurements
- I Arouter framework analysis
- How to generate code-11 barcode in batch through TXT file
- Which insurance company is the most cost-effective for purchasing serious illness insurance?
- Banknext microservice: a case study
- "Tencent conference": how to operate and maintain efficiently in the face of exponential growth of business?
- Even if you don't learn gradle, these common development operations are worth mastering
- Easygbs service is killed because the user redis is infected with the mining virus process. How to solve and prevent it?
猜你喜欢

聊聊内存模型和内存序

【曾书格激光SLAM笔记】Gmapping基于滤波器的SLAM

R tree of search tree
![Analysis of China's integrated circuit industry chain in 2021: huge downstream market demand [figure]](/img/de/d73805aaf4345ca3d2a7baf85aab8d.jpg)
Analysis of China's integrated circuit industry chain in 2021: huge downstream market demand [figure]

Banknext microservice: a case study

【owt】owt-client-native-p2p-e2e-test vs2017构建2 :测试单元构建及运行

Google Earth Engine(GEE)——长时间序列逐月VCI数据提取分析和面积计算(墨西哥为例)

【机器学习】 吴恩达机器学习作业 ex2逻辑回归 Matlab实现
![[quick view] Analysis on the development status and future development trend of the global and Chinese diamond cultivation industry in 2021 [figure]](/img/f1/972a760459a6d599b5681aa634df09.jpg)
[quick view] Analysis on the development status and future development trend of the global and Chinese diamond cultivation industry in 2021 [figure]

【二分】leetcode1011. Capacity To Ship Packages Within D Days
随机推荐
If there is a smart bus visualization platform, can "beginning" restart indefinitely?
【LeetCode】翻转链表II
Auto rename when uploading pictures on WordPress media
Detailed discussion on modular architecture design of MCU firmware
Analysis on the development of duty-free industry in Hainan Province in 2021: the implementation of the new policy makes the duty-free market in Hainan more "prosperous" [figure]
Firewall and IP security policy configuration
RTOS system selection for charging point software design
How to implement collection sorting?
Analysis of China's integrated circuit industry chain in 2021: huge downstream market demand [figure]
Tcapulusdb Jun · industry news collection (V)
Form submit onclick and onsubmit
Even if you don't learn gradle, these common development operations are worth mastering
CentOS install redis
Troubleshooting and resolution of asydss virtual live broadcast status synchronization and service downtime
The MIUI 13 development version of Xiaomi mobile phone blocks the chrome application and cannot be opened after installation
[advanced Android] entrusted by kotlin
Learning summary of spanquery source code
【机器学习】 吴恩达机器学习作业 ex2逻辑回归 Matlab实现
YouTube security scenarios
Know res.send() and res.end() of Express