Professional Documents
Culture Documents
Source Code:
#include<iostream>
using namespace std;
while(low<=high)
{
mid=(low+high)/2;
if(x==arr[mid])
{
return mid;
}
else if(x>arr[mid])
{
low=mid+1;
}
else if(x<arr[mid])
{
high=mid-1;
}
return -1;
}
int main(){
string confirm;
cout<<"------WELCOME TO THE ELEMENT SEARCHER!------"<<endl;
int arr[50],n,i;
cout<<"Enter the size of the Array: ";
cin>>n;
cout<<"Enter the elements of the Array: ";
for(i=0;i<n;i++)
cin>>arr[i];
int x;
int mode;
cout<<"Searching Algorithm available\n"
<<"\n__"
<<"\n1. LINEAR SEARCH"
<<"\n2. BINARY SEARCH"
<<"\n___"
<<"\n Choose your method: ";
cin>>mode;