-->
当前位置:首页 > 题库 > 正文内容

程序填空题:顺序查找

Luz4年前 (2021-05-10)题库4653
顺序查找。
```c++
#include
using namespace std;
#define MAXSIZE 100
#define OK 1;

typedef struct{
int key;
}ElemType;

typedef struct{
ElemType *R;
int length;
}SSTable;

int Create_SSTable(SSTable &L)
{ int n;
cin >> n;
for(int i=1;i<=n;i++)
{
cin >> L.R[i].key;
L.length++;
}
return 1;
}

int Search_Seq(SSTable ST, int key){
int i;
@@[ST.R[0].key](2) = key;
for(i = ST.length; @@[ST.R[i].key!=key](2); --i);
return i;
}

int main()
{
SSTable ST;
int key;
int result;
ST.R=new ElemType[MAXSIZE];
ST.length=0;
Create_SSTable(ST);
cin >> key;
result=Search_Seq(ST, key);
if(result)
cout << "search success";
else
cout << "search failed";
return 0;
}

```
### 输入样例:
第一行输入一个数n,第二行输入n个数,第三行输入要查找的数key。
```in
7
24 53 45 45 12 24 90
24
```

### 输出样例:
若查找成功,输出“search success”,查找失败,输出“search failed”。
```out
search success
```





答案:
第1空:ST.R[0].key

第2空:ST.R[i].key!=key

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。