#include <cstdlib>
#include <iostream>
using namespace std;
/*int LinearSearch (int a[],int x, int n ){
for(int i=0;i<n;i++)
if (a[i]==x) return i;
return-1;
}*/
int binarySearch (int a[], int n, int x){
int mid,low=0,high=n;
while(low<=high){
mid=(low+high)/2;
if(x==a[mid]) return mid;
if(x>a[mid])low=mid++;
else high=mid-1;
}
return-1;
}
int main (int argc,char *argv[]) {
int a[100];
int i,n,k;
cout <<" massiviin hemjee"; cin>>n;
int too=0;
for (i=0;i<n;i++)
{
a[i] = too;
too = too+2;
cout<<a[i]<<" ";
}
cout<<endl;
int x;
cin>>x;
int s=binarySearch (a,n,x);
cout<<a[s] cout;
/*int x; cin>>x; int s = LinearSearch(a, x, n); cout<<s; */
system("PAUSE");
return EXIT_SUCCESS;
}
Админ Ээгий
No comments:
Post a Comment