二分查找 递归 没学好 报错不知道怎么改 求助
#include <iostream.h>int BinarySearch(int s[100],int x,int low,int high)
{
if(low>high)
return -1;
int mid=(low+high)/2;
if(x==s[mid])
return mid;
else if(x>mid)
return BinarySearch(s,x,mid+1,high);
else
return BinarySearch(s,x,low,mid-1);
}
void main()
{
int s[100],n,x,i,mid;
cout<<"输入元素个数n=";
cin>>n;
cout<<"输入需查找x=";
cin>>x;
cout<<"输入数组为:";
for(i=1;i<=n;i++)
cin>>s[i];
int low=s[1],high=s[n];
mid=BinarySearch(s[100],x,low,high);
cout<<"该元素位于第"<<mid<<"位"<<endl;
}