© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu
Quick Links
Easy Studies


CPP Program To Implement Binary Search :

#include #include #include class BinarySearch { int a[25],n; public: void getdata(); void sorting(); void binarysearch(); }; void BinarySearch :: getdata() { clrscr(); cout<>n; cout<>a[i]; } void BinarySearch :: sorting() { int temp; for(int i=0;ia[j+1]) { temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } } } } void BinarySearch :: binarysearch() { int high,low,mid,s; cout<>s; high=n-1; low=0; while(low<=high) { mid=(low+high)/2; if(s>a[mid]) low=mid+1; else if(s

SAMPLE INPUT AND OUTPUT:

  Enter the elements
5
4
3
2
1

Sorted list
1
2
3
4
5

Enter the element to be searched : 5

The element 5 is found.

 
SLogix Student Projects

⇓Student Projects⇓
⇑Student Projects⇑
bottom