当前位置:网站首页>折半查找法
折半查找法
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 should be prepared to develop the company's official website?
- Analysis on demand and market scale of China's steamed stuffed bun industry in 2020 [figure]
- Tcapulusdb Jun · industry news collection (V)
- New configuration of Alipay
- Tencent released the global DDoS threat report in 2021: DDoS threat has become the preferred extortion method for criminal gangs
- JS Part 4
- 【LeetCode】23. 合并K个升序链表
- What are the advantages of the completely free and open source flutter? How to learn about flutter?
- Weekly Postgres world news 2022w03
- On the way home from the Spring Festival transportation, traffic visualization will escort you
猜你喜欢

Banknext microservice: a case study

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]

mysql常用指令

新版kali切换最高账户
![Analysis on development history, industrial chain, output and enterprise layout of medical polypropylene in China in 2020 [figure]](/img/28/ebfc25ec288627706e15a07e6bdb77.jpg)
Analysis on development history, industrial chain, output and enterprise layout of medical polypropylene in China in 2020 [figure]
![Analysis on the development status of China's watch industry in 2021: a large number of electric watches are imported [figure]](/img/ca/672bfe49c8123da8679b2abeb43a2e.jpg)
Analysis on the development status of China's watch industry in 2021: a large number of electric watches are imported [figure]

innodb_ruby 视角下 MySQL 记录增删改

Encryption related to returnee of national market supervision public service platform

centos7 安装 MySQL 及配置 innodb_ruby

聊聊内存模型和内存序
随机推荐
Not just offline caching- On how to make good use of serviceworker
Salesforce heroku (V) application in salesforce (canvasapp)
What is the potential of dmail based on Web3.0? First round financing of $10 million?
How to make distribution box label
【LeetCode】翻转链表II
The MIUI 13 development version of Xiaomi mobile phone blocks the chrome application and cannot be opened after installation
"Tencent conference": how to operate and maintain efficiently in the face of exponential growth of business?
What is the difference between the poll () method and the remove () method?
Brief introduction to arm architecture
innodb_ruby 视角下 MySQL 记录增删改
【LeetCode】23. 合并K个升序链表
Bi skills - authority control
Simply use the pagoda to build WordPress
How to get started with apiccloud app and multi terminal development of applet based on zero Foundation
How to batch generate jan13 barcode
1-1VMware介绍
【二分】leetcode1011. Capacity To Ship Packages Within D Days
MCU model selection for charging point system design
JSON. Function of the stringify() optional parameter
Is LinkedList a one-way linked list or a two-way linked list?