题目要求先输入十五个数,然后对这十五个数排序,之后再输入一个数,用对半查找法查找是不是在这输入的十五个数里面,如果在就输出这个数的位置,不在就输出“there is no such a number”,我前面的都对,就是在折半查找的时候找不出来,每次都是“there is no such a number”,我用VC里面的测试过了,就是那一步的K有问题,但是具体什么问题我不知道希望各位能帮忙!
#include
#define MEM 15
int order(int array[],int max)
{
for(int i=0;iarray[mid])
low=mid+1;
else high=mid-1;
}
return -1;
}
void main()
{
int mark[MEM];
coutmark;
}
cout>find;
/*int a[10]={12,52,86,95,125,145,163,196,200,254};
int m=search(a,95,10);cout<<"M="<<m<<endl;*/
int k=search(mark,find,MEM);//查找
if(k==-1)
{
cout<<"there is no such a number."<<endl;
}
else cout<<"the "<<k<<"number is you want"<<endl;
}
|