📄 6.1.c
字号:
#include<stdio.h>
struct SSTable
{int *elem;
int length;
};
struct SSTable ST;
void Creat_SSTable()
{int i;
printf("please input the number of elem:\n");
scanf("%d",&ST.length);
getchar();
ST.elem=(int *)malloc((ST.length+1)*sizeof(int));
printf("please input the elem:\n");
for(i=1;i<=ST.length;i++)
scanf("%d",&ST.elem[i]);
getchar();
}
int Search_Bin(int e)
{int low=1,high=ST.length,mid;
while(low<=high)
{mid=(low+high)/2;
if(e==ST.elem[mid])
return mid;
else
if(e<ST.elem[mid])
high=mid-1;
else
low=mid+1;
}
return 0;
}
void main(void)
{int e,n;
Creat_SSTable();
printf("please input the elem which you want search:\n");
scanf("%d",&e);
getchar();
n=Search_Bin(e);
if(n)
printf("the locate is:%d\nsuccess!\n",n);
else
printf("error!\n");
getchar();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -