fibonacci检索??求助啊!
#include <stdio.h>#define max 100 /*定义被检索的数组元素个数的最大个数*/
typedef int keytype;
typedef int datatype;
typedef struct
{keytype key;
datatype other;
}rectype;
rectype R[];
int fibonacci(n) /*定义fibonacci数为整型*/
int n;
{if(n==0)
return(0);
else
if(n==1)
return(1);
else
return (fibonacci(n-1)+fibonacci(n-2));
} /*对fibonacci数的定义*/
int fibosrch(rectype R[],keytype k,int low,int m) /*fibonacci检索*/
{int i,n=0,loc;
do
{n++;
}while(fibonacci(n)<m);
i=fibonacci(n-1)+low;
if(R[i].key==k)
loc=i;
else
if(R[i].key>k)
{m=i-low-1;
fibonacci(R,k,m,low);
}
else
if(R[i].key<k)
{low=i;
m=m-i;
fibonacci(R,k,m,low);
}
return loc;
}
void main()
{int i,k,a,m=7,low=0;
/*rectype R;*/
printf("input the k:\n");
scanf("%d",&k);
printf("input the shuzu:\n");
for(i=1;i<=m;i++)
scanf("%d",R[i].key);
a=fibosrch(R,k,low,m);
printf("%d",a);
}
提示输入时发生冲突,请高手指教!!!