Binary Search Technique Program in C++

Binary Search Technique Program in C++

Program to implement the Binary Search Technique in C++

Binary Search Technique Program in C++
Binary Search Technique
#include<iostream.h>
#include<conio.h>
void main()
{
int List[100],n,s,i,ch;
cout<<"Enter the size of the list\n";
cin>>n;
cout<<"Enter the elements of the list in Ascending Order\n";
for(i=0;i<n;i++)
cin>>List[i];
do{
cout<<"Enter the element to Search\n";
cin>>s;
int l=0, h=n-1,m;
do{
m=(l+h)/2;
if(s==List[m])
break;
else if(s<List[m])
h=m-1;
else
l=m+1;
}while(l<=h);
if(l<=h)
cout<<"The Search element "<<s<<" FOUND at "<<m+1<<" position\n";
else
cout<<"Element Not FOUND\n";
cout<<"Do u want to continue*(1/0)\n";
cin>>ch;
  }while(ch!=0);
}

Comments