Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Binary Search Program in C++

 This program contains some errors you need to remove.
___________________________________________________
#include
using namespace std;

class BinarySearch
{
int i;
int n;
public:
void b_search(int *, int, int);
 };

 void BinarySearch :: b_search(int a[],int n, int dataitem)
 {
int start, end, mid, index, f=0;
start=0;
end = n-1;
coutwhile( (start {
mid = (( start + end)/2);
if(dataitem == a[mid])
{
cout f=1;
} else if( dataitem {
end = mid -1;
}  else
start=mid +1;
if(f==0){
cout           }
}

int main()
{
int a[8], n, dataitem, int i;
BinarySearch bs;
cout cin>>n;
cout for(i=0 ; i {
cin>> a[i];
}
cout cin>> dataitem;
bs.b_search(a,n,dataitem);

return 0;
}



This post first appeared on Computex Academy, please read the originial post: here

Share the post

Binary Search Program in C++

×

Subscribe to Computex Academy

Get updates delivered right to your inbox!

Thank you for your subscription

×