CH7_3.C
上传用户:lgb298
上传日期:2013-03-22
资源大小:1025k
文件大小:1k
- #include <stdio.h>
- typedef struct
- { int key;
- int link;
- }SD;
- typedef struct
- { int key;
- /*float info;*/
- }JD;
- int blocksrch(JD r[],SD nd[],int b,int k,int n)
- { int i=1,j;
- while((k>nd[i].key)&&(i<=b)) i++;
- if(i>b) { printf("nNot found");
- return(0);
- }
- j=nd[i].link;
- while((j<n)&&(k!=r[j].key)&&(r[j].key<=nd[i].key))
- j++;
- if(k!=r[j].key) j=0;
- return(j);
- }
- void main()
- {
- static JD r[]={0,22,12,13,8,9,20,33,42,44,38,24,48,60,58,74,57,86,53};
- static SD nd[]={{0,0},{22,1},{48,7},{86,13}};
- int i,n=18,b=3;
- int key;
- printf("Input the key :");
- scanf("%d",&key);
- i=blocksrch(r,nd,b,key,n);
- if(!i)
- printf("Not foundn");
- else
- printf("the index of %d is %dn",key,i);
- }