Cpp1.exe 遇到问题需要关闭,我们对此引起的不便表示抱歉。怎么回事??? 5
#include<stdio.h>#include<malloc.h>typedefintKeyElem;typedefstruct{KeyElemkey;}ElemTy...
#include<stdio.h>
#include <malloc.h>
typedef int KeyElem;
typedef struct
{
KeyElem key;
}ElemType;
typedef struct {
ElemType *elem;
int length;
}SSTable;
int Search_Bin ( SSTable ST, KeyElem key ) {
int i;
ST.elem[0].key=key;
for(i=ST.length; !(ST.elem[i].key);--i);
return i;
}
/*{
int low = 1,high = ST.length,mid;
while (low <= high) {
mid = (low + high) / 2;
if (kval == ST.elem[mid].key ) return mid;
else
if ( kval < ST.elem[mid].key ) high = mid - 1;
else low = mid + 1;
}
return 0;
} */
int main()
{int low,hight,n,i;
SSTable ST;
int kval,a;
//ST=getchar()();
ST.elem=(ElemType*)malloc(sizeof(ElemType)*10);
ST.length=10;
for(i=0;i<10;i++){
scanf("%d",&a);
ST.elem[i].key=a;
}
printf("请输入要查找的数");
scanf("%d",kval);
n=Search_Bin (ST,kval ) ;
printf("%d\n",n);
return 0;
} 展开
#include <malloc.h>
typedef int KeyElem;
typedef struct
{
KeyElem key;
}ElemType;
typedef struct {
ElemType *elem;
int length;
}SSTable;
int Search_Bin ( SSTable ST, KeyElem key ) {
int i;
ST.elem[0].key=key;
for(i=ST.length; !(ST.elem[i].key);--i);
return i;
}
/*{
int low = 1,high = ST.length,mid;
while (low <= high) {
mid = (low + high) / 2;
if (kval == ST.elem[mid].key ) return mid;
else
if ( kval < ST.elem[mid].key ) high = mid - 1;
else low = mid + 1;
}
return 0;
} */
int main()
{int low,hight,n,i;
SSTable ST;
int kval,a;
//ST=getchar()();
ST.elem=(ElemType*)malloc(sizeof(ElemType)*10);
ST.length=10;
for(i=0;i<10;i++){
scanf("%d",&a);
ST.elem[i].key=a;
}
printf("请输入要查找的数");
scanf("%d",kval);
n=Search_Bin (ST,kval ) ;
printf("%d\n",n);
return 0;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询