当前位置:网站首页>Learning history of C language
Learning history of C language
2020-11-09 12:53:00 【osc_mra0q9h6】
Learning goals :
It's hard for us to understand , Let's look at the simple ones first , come on. L To rush !
Learning time :
2020 year 11 month 1 Japan
Learning output :
c Language dichotomy to achieve data search
#include<stdio.h>
/******************
Function implementation dichotomy
*******************/
int binary_research(int arr[],int length,int element)
{
int left = 0;
int right = 0;
right = length - 1;
while (left <= right) {
int mid = (left + right) / 2;
if (arr[mid] > element) {
right = mid - 1;
} else if {
(arr[mid] < element)
left = mid + 1;
} else {
return mid;
}
}
return -1;
}
int main()
{
int numStr[] = {
4, 7, 8, 45, 64, 123, 564, 586, 614, 688, 999};
int left = 0;
int right = 0;
int mid = 0;
int checkNum = 0;
int numLen = 0;
printf(" The string to look up is :\nnumStr[] = {4, 7, 8, 45, 64, 123, 564, 586, 614, 688, 999}\n");
scanf("%d", &checkNum);
numLen = sizeof(numStr) / sizeof(int);
//mid = binary_research(numStr, numLen, checkNum);
right = numLen - 1;
mid = (left + right) / 2;
// Common method to achieve two distribution search
while (left <= right) {
if (numStr[mid] > checkNum) {
right = mid -1;
} else if (numStr[mid] < checkNum) {
left = mid + 1;
} else {
break;
}
mid = (left + right) / 2;
}
printf("mid = %d\n", mid);
return 0;
}
版权声明
本文为[osc_mra0q9h6]所创,转载请带上原文链接,感谢
边栏推荐
- 苏宁基于知识图谱的大规模告警收敛和根因定位实践
- Method of creating flat panel simulator by Android studio
- After SQL group query, get the first n records of each group
- 用一种简单的方式实现终端文字粘贴板
- 导师制Unity网课 双十一优惠报名进行中
- SEO见风使舵,是对还是错?
- “开源软件供应链点亮计划 - 暑期 2020”公布结果 基于 ChubaoFS 开发的项目获得最佳质量奖
- 安全(杂记)
- Three practical skills of Medical Project Management
- Vscode plug-in configuration pointing North
猜你喜欢
SEO见风使舵,是对还是错?
外贸自建网站域名的选择— Namesilo 域名购买
解密未来数据库设计:MongoDB新存储引擎WiredTiger实现(事务篇)
未来中国电信将把云计算服务打造成为中国电信的主业
Configure switch trunk interface traffic local priority forwarding (cluster / stack)
Android 集成支付的四部曲
Technology and beauty are so expensive, it's better to find consultants | aalab enterprise consulting business
JVM学习(五) -执行子系统
Fedora 33 Workstation 的新功能
The choice of domain name of foreign trade self built website
随机推荐
Android Development - service application, timer implementation (thread + service)
How to use function framework to develop large web application
Explain Python input() function: get user input string
Download Netease cloud music 10W + music library with Python
天啦撸!打印日志竟然只晓得 Log4j?
Detailed explanation of [golang] GC
Reading design patterns adapter patterns
Navigation component of Android architecture (2)
Reduce of Flink
Interface tests how to pass files in post requests
走进京东 | 中国空间技术研究院青年创新联盟成员莅临参观京东总部
android studio AIDL的使用
A simple ability determines whether you will learn!
JVM学习(六)-内存模型和线程
面试了一位33岁Android程序员,只会面向百度编程,居然要25k,被我一顿怼
块级元素和行内元素
Android 集成支付的四部曲
解密未来数据库设计:MongoDB新存储引擎WiredTiger实现(事务篇)
EFF 认为 RIAA 正在“滥用 DMCA”来关闭 YouTube-DL
彩虹排序 | 荷兰旗问题