⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch7_2

📁 数据结构的一些小算法
💻
字号:
#include <stdio.h>
#define M 500
typedef struct
{  int key;
 /*  float info;*/
}JD;

int binsrch(JD r[],int n,int k)
{  int low,high,mid,found;
   low=1;  high=n; found=0;
   while((low<=high)&&(found==0))
   {  mid=(low+high)/2;
      if(k>r[mid].key)  low=mid+1;
      else if(k==r[mid].key)  found=1;
      else   high=mid-1;
   }
   if(found==1)
      return(mid);
   else
      return(0);
}

void main()
{
    static JD r[]={0,5,13,19,21,37,56,64,75,80,88,92};
    int i,n=11;
    int key;
    printf("Input the key you want to search:");
    scanf("%d",&key);
    i=binsrch(r,n,key);
    if(!i)
      printf("Not found\n");
    else
      printf("the index of %d is %d\n",key,i);
}

⌨️ 快捷键说明

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