当前位置:网站首页>A half search method for sequential tables
A half search method for sequential tables
2022-06-25 12:45:00 【yyy_ zxc】
#include "seqlist.cpp" // Basic algorithm of inclusion sequence table
// Half search algorithm
int BinSearch(RecType R[],int n,KeyType k){
int low=0,high=n-1,mid,count=0;
while(low<=high){ // When low>high when , Indicates that the search failed
mid=(low+high)/2;
printf(" The first %d Compare it to : stay 【%d,%d】 Compare elements in R[%d]:%d\n",
++count,low,high,mid,R[mid].key);
if(R[mid].key==k) // Search successful return
return mid+1;
if(R[mid].key > k) // Continue to R[low...mid-1] Search for
high=mid-1;
else // Continue to R[mid+1...high] Search for
low=mid+1;
}
return 0;
}
int main(){
RecType R[MAXL];
KeyType k = 9;
int a[]={1,2,3,4,5,6,7,8,9,10};
int i,n=10;
CreateList(R,a,n); // Create a sequence table
printf(" Keyword sequence :");
DispList(R,n);
printf(" lookup %d The comparison process is as follows :\n",k);
if((i=BinSearch(R,n,k))!=0)
printf(" Elements %d The position is %d\n",k,i);
else
printf(" Elements %d Not in table \n",k);
return 1;
}

边栏推荐
- Thinkphp3 reinforcement i() function filter single quotation marks
- JS array length is defined
- flutter 收到推送后自动消失问题
- PHP parsing QR code content
- 阿里稳定性之故障应急处理流程
- ECSHOP commodity page multi-attribute batch purchase plug-ins ECSHOP wholesale plug-ins multi-attribute order placing, multi-attribute batch purchase of commodities
- 顺序表的折半查找法
- ThinkPHP upload image compression size
- Spicy food advertising e-commerce system development function and spicy food advertising e-commerce app system development source code sharing
- PPT绘论文图之导出分辨率
猜你喜欢

PPT绘图之AI助力论文图

Penetration tool environment - installing sqli labs in centos7 environment

初识CANOpen

Parse JSON format data and save it to entity class

Zhangxiaobai's road of penetration (IV) -- detailed explanation of XSS cross site script vulnerabilities

The server reported an error 503 service unavailable:the system returned: (71) protocol error

线上服务应急攻关方法论

三入职场!你可以从我身上学到这些(附毕业Vlog)

Elemtnui select control combined with tree control to realize user-defined search method

Embedded software development written examination and interview notes (latest update: February 17, 2022)
随机推荐
PHP replaces the key of a two-dimensional array with a specified element value
Parse JSON format data and save it to entity class
Array reorder based on a field
Slice() and slice() methods of arrays in JS
Lighten the source code -- lighten the app system development function introduction to the beautiful world lighten the app system development source code in China
Fun pocket mall -- sharing the development source code of fun pocket app system
重装cuda/cudnn/pytorch
【AI助力科研】loss曲线傻瓜式绘制
JS function exercises
JQ dynamic setting radio does not take effect when selected
Qt5 multi thread operation implemented by object base class and use of movetothread method
初识CANOpen
Common software numerical filtering methods (I) have been applied
2021-10-21
JS array de duplication
ECSHOP quickly purchases goods, simplifies the shopping process, and improves the user experience through one-step shopping
Laravel task scheduling
Laravel is not logged in and cannot access the background by entering the URL
Jenkins Pipeline使用
线上服务应急攻关方法论