当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- Configure switch trunk interface traffic local priority forwarding (cluster / stack)
- Jsliang job series - 08 - handwritten promise
- 利用 Python 一键下载网易云音乐 10W+ 乐库
- 未来中国电信将把云计算服务打造成为中国电信的主业
- FGC online service troubleshooting, this is enough!
- Decrypting the future database design: implementation of mongodb's new storage engine wiredtiger (transaction)
- What are the implementations of distributed locks?
- inet_ Pton () and INET_ Detailed explanation of ntop() function
- 10款必装软件,让Windows使用效率飞起!
- 分库分表的 9种分布式主键ID 生成方案,挺全乎的
猜你喜欢
Understanding runloop in OC
为wget命令设置代理
Tutorial system unity online course double 11 preferential registration is in progress
c语言小白学习历程第六篇
Introduction to zero based im development (4): what is message timing consistency in IM systems?
Android 集成支付的四部曲
Oh, my God! Printing log only knows log4j?
Rainbow sorting | Dutch flag problem
解密未来数据库设计:MongoDB新存储引擎WiredTiger实现(事务篇)
使用TreeView树型菜单栏(递归调用数据库自动创建菜单)
随机推荐
inet_pton()和inet_ntop()函数详解
Idea rest client, yes, I haven't opened postman yet
vscode 插件配置指北
An attempt to read or write to protected memory occurred using the CopyMemory API. This usually indicates that other memory is corrupted.
The use of Android studio Aidl
导师制Processing网课 双十一优惠进行中
从汇编的角度看pdb文件
Download Netease cloud music 10W + music library with Python
解密未来数据库设计:MongoDB新存储引擎WiredTiger实现(事务篇)
Reduce of Flink
彩虹排序 | 荷兰旗问题
除了解析域名,DNS还能干吗?
Nine kinds of distributed primary key ID generation schemes of sub database and sub table are quite comprehensive
IDEA解决yml配置文件中文输出乱码问题
Mobile security reinforcement helps app achieve comprehensive and effective security protection
Flink 系例 之 Reduce
Solve the problem of idea shortcut key Alt + insert invalid
Efficient estimation of word representations in vector space
【分布式】分布式锁都有哪些实现方案?
Interface tests how to pass files in post requests