ch7_3.c

来自「数据结构( C语言版) 讲义daima数据结构( C语言版) 讲义daima」· C语言 代码 · 共 38 行

C
38
字号
#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 found\n");
    else
      printf("the index of %d is %d\n",key,i);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?