当前位置:网站首页>折半查找法
折半查找法
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;
}边栏推荐
- The compatibility of remotefx schemes is related to multiple factors
- Summary of some precautions and problems in the use of tars framework (mengxinxiang)
- 直接插入排序
- TRTC zero foundation -- Video subscription on the code
- What are the advantages and difficulties of introducing AI into ISP Technology
- JS Part 4
- Encryption related to returnee of national market supervision public service platform
- Preliminary sequencing problem
- Parsing the implementation of easygbs compatible token as parameter passing
- 聊聊内存模型和内存序
猜你喜欢

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

LRU cache

JS Part 4
![Analysis of the number of urban residents covered by basic medical insurance, their treatment and medical treatment in other places in China in 2021 [figure]](/img/81/4d3cb059f700dd9243645e64023be7.jpg)
Analysis of the number of urban residents covered by basic medical insurance, their treatment and medical treatment in other places in China in 2021 [figure]

Fetch request details

新版kali切换最高账户
![Analysis on demand and market scale of China's steamed stuffed bun industry in 2020 [figure]](/img/4b/dd272f98b89a157180bf68570d2763.jpg)
Analysis on demand and market scale of China's steamed stuffed bun industry in 2020 [figure]

第一批00后下场求职:不要误读他们的“不一样”

Using jhipster to build microservice architecture

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]
随机推荐
What is the difference between the poll () method and the remove () method?
New configuration of Alipay
[burning] Tencent cloud high tech computing platform HTPC cloud elastic cluster release!
【贪心】leetcode991. Broken Calculator
Troubleshooting and resolution of asydss virtual live broadcast status synchronization and service downtime
Gx3001q UI instructions for upgrading 8-bit color to 16 bit color
数据交易怎样实现
What should be prepared to develop the company's official website?
How to get started with apiccloud app and multi terminal development of applet based on zero Foundation
Tencent cloud tcapulusdb helps tmeland, the first virtual Music Carnival in China, and tens of thousands of people cross the new year together!
【LeetCode】两数之和II
【机器学习】 吴恩达机器学习作业 ex2逻辑回归 Matlab实现
Summary of some precautions and problems in the use of tars framework (mengxinxiang)
新版kali切换最高账户
RTOS system selection for charging point software design
Analysis on the development of China's graphene industry chain in 2021: with the support of energy conservation and environmental protection policies, the scale of graphene industry will continue to e
Composition and simple classification of IP addresses
Stress testing with locust on rainbow
What about the high cost of storage system? The original computer room can save so much money!
How to make distribution box label