Resources » Articles/Knowledge Sharing » Computer & Technology

C++ program for binary search


Posted Date: 15-Mar-2008  Last Updated:   Category: Computer & Technology    
Author: Member Level: Gold    Points: 2



//binary search
#include
void main()
{
int arr[25];
int start=0,end=0,middle,n;
int item;
cout<<"enter the no of elements in which you want to perform binary search:";
cin>>n;
cout<<"Enter the sorted element"<
for(int i=0;i {
cout<<"enter the element "< cin>>arr[i];
}
end=n-1;
middle=(start + end)/2;
cout<<"ENTER THE ELEMENT YOU WANT TO SEARCH :";
cin>>item;
while(arr[middle]!=item && start<=end)
{
if(arr[middle] start=middle+1;
else
end=middle-1;
middle=(start+end)/2;
}
if(arr[middle]==item)
cout< else
cout<

}


Did you like this resource? Share it with your friends and show your love!




Responses to "C++ program for binary search"
Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Submit Article     Return to Article Index

    Awards & Gifts
    Active Members
    TodayLast 7 Daysmore...

    ISC Technologies, Kochi - India. Copyright © All Rights Reserved.