当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- 解决IDEA快捷键 Alt+Insert 失效的问题
- CSP-J/S 2020考前注意事项
- 导师制Processing网课 双十一优惠进行中
- Android Development - service application, timer implementation (thread + service)
- Detailed explanation of [golang] GC
- 从汇编的角度看pdb文件
- Rainbow sorting | Dutch flag problem
- Solve the problem of idea shortcut key Alt + insert invalid
- After SQL group query, get the first n records of each group
- 如何用函数框架快速开发大型 Web 应用 | 实战
猜你喜欢
随机推荐
Python loading voice class custom dataset
An attempt to read or write to protected memory occurred using the CopyMemory API. This usually indicates that other memory is corrupted.
JVM学习(四)-垃圾回收器和内存分配
Adobe Experience Design /Xd 2020软件安装包(附安装教程)
Rainbow sorting | Dutch flag problem
使用TreeView树型菜单栏(递归调用数据库自动创建菜单)
Method of creating flat panel simulator by Android studio
After SQL group query, get the first n records of each group
03.优先链接模型
Explain Python input() function: get user input string
vscode 插件配置指北
未来中国电信将把云计算服务打造成为中国电信的主业
Using rem, the font size changes when the screen zooms
Decrypting the future database design: implementation of mongodb's new storage engine wiredtiger (transaction)
SQL Chapter 2 Chapter 3
Open source ERP recruitment
Online course of tutorial system processing is in progress
Setting up a proxy for the WGet command
Reading design patterns adapter patterns
Well, these four ways to query the maximum value of sliding window are good

