#include <iostream>
using namespace std;
#define siz 100000000
int n;
int a[siz];
void Binary_search(int l, int h, int s)
{
if(h<0||l==n) cout<<"Not Found"<<endl;
else
{
int mid=(l+h)/2;
if(a[mid]==s) cout<<"Found"<<endl;
else if(s<mid) Binary_search(l,mid-1,s);
else Binary_search(mid+1,h,s);
}
}
int main()
{
int s;
while(cin>>n)
{
for(int i=0;i<n;i++) cin>>a[i];
cin>>s;
Binary_search(0,n-1,s);
}
return 0;
}
Binary Search
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment