📄 l81.cpp
字号:
//顺序查找的实现
#include<iostream.h>
const int n=10 ;
typedef int elemtype; //n为表的最大长度
struct node
{elemtype key; //key为关键字,类型设定为elemtype
};
node R[n+1]={0,2,4,6,8,1,3,5,7,10,9};
int seqsearch (node R[n+1],elemtype k) //在表R中查找关键字值为K的元素
{
R[0].key=k; int i=n; //从表尾开始向前扫描
while(R[i].key!=k) i--;
return i;
}
void main()
{ int k,j;
cout<<" 线性表为:"<<endl;
for(j=1;j<=n;j++) cout<<R[j].key<<" ";
cout<<endl<<"请输入待查元素";
cin>>k;
j=seqsearch(R,k);
cout<<endl<<"待查元素"<<k<<"的位置为:"<<j<<endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -