当前位置:网站首页>利用二分法从数组中寻找具体数值
利用二分法从数组中寻找具体数值
2022-07-24 05:16:00 【泡泡牛奶】
#include <stdio.h>
int main()
{
int i = 0;
int arr[] = { 1,2,3,4,5,6,7,8,9,10 };
int sz = sizeof(arr) / sizeof(arr[0]);
int lift = 0;//左下标
int right = sz - 1;//右下标
scanf("%d", &i);//接收要找的数字
while ( lift <= right)
{
int mid = (lift + right) / 2;
if (arr[mid] > i)
right = mid -1;
else if (arr[mid] < i)
lift = mid + 1;
else if (arr[mid] == i)
{
printf("下标为 %d", mid);
break;
}
}
if (lift > right)
printf("没找到");
return 0;
}
//利用二分法从一串数组中寻找具体数字
//扩展思想:若数组内容足够大时,可以更快找出目标边栏推荐
- anaconda常用命令的整理
- Source code compilation!!
- Introduction to threads
- SSM整合
- How to avoid the most common mistakes when building a knowledge base?
- 2. Input a circle radius r, when r > = 0, calculate and output the area and perimeter of the circle, otherwise, output the prompt information.
- Add, delete, modify and check JDBC
- Pointer learning diary (I)
- Chapter5 foundation of deep learning
- C语言进阶篇 七.程序的编译和预处理
猜你喜欢
随机推荐
[deep learning] (III) image classification
一步一步带你学C(其一)
I'm interested in reading efficient reading - the most cost-effective self investment
MySQL insight
Scikit learn -- steps of machine learning application development
JMeter upload and download files
Jsp+dao integration
Generics and annotations
统计学之样本和总体的关系: 样本成功比例+中心极限定理(样本均值)
反射
一步一步带你学C(其二)
Performance test process
跟李沐学ai 线性回归 从零开始的代码实现超详解
Problems encountered in configuring Yum source
使用swagger2markup生成API文档
Chapter5 foundation of deep learning
AiN 0722 签到
JMeter FAQs
Industry relevance of stock price trend
Generator generator, which generates only two methods









