第十三周项目一

/*
Copyright (c++) 2017,烟台大学计算机与控制工程学院
文件名称:jcy
作 者:贾存钰
完成日期:2017年11月29日
问题描述:线性表的顺序查找

*/

[cpp]  view plain  copy
  1. #include <stdio.h>  
  2. #define MAXL 100  
  3. typedef int KeyType;  
  4. typedef char InfoType[10];  
  5. typedef struct  
  6. {  
  7.     KeyType key;                //KeyType为关键字的数据类型  
  8.     InfoType data;              //其他数据  
  9. } NodeType;  
  10. typedef NodeType SeqList[MAXL];     //顺序表类型  
  11.   
  12. int SeqSearch(SeqList R,int n,KeyType k)  
  13. {  
  14.     int i=0;  
  15.     while (i<n && R[i].key!=k)  //从表头往后找  
  16.         i++;  
  17.     if (i>=n)  
  18.         return 0;  
  19.     else  
  20.         return i+1;  
  21. }  
  22. int main()  
  23. {  
  24.     int i,n=10;  
  25.     int result;  
  26.     SeqList R;  
  27.     KeyType a[]= {2,3,1,8,5,4,9,0,7,6},x=9;  
  28.     for (i=0; i<n; i++)  
  29.         R[i].key=a[i];  
  30.     result = SeqSearch(R,n,x);  
  31.     if(result>0)  
  32.         printf("序列中第 %d 个是 %d\n",result, x);  
  33.     else  
  34.         printf("木有找到!\n");  
  35.     return 0;  
  36. }  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值