<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Binary Search Algorithm | Student Projects</title>
	<atom:link href="https://studentprojects.in/tag/binary-search-algorithm/feed/" rel="self" type="application/rss+xml" />
	<link>https://studentprojects.in</link>
	<description>Microcontroller projects, Circuit Diagrams, Project Ideas</description>
	<lastBuildDate>Thu, 27 Jan 2011 11:46:46 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.7</generator>
	<item>
		<title>Program to implement Binary Search Algorithm</title>
		<link>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-advanced/program-to-implement-binary-search-algorithm/</link>
					<comments>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-advanced/program-to-implement-binary-search-algorithm/#comments</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Tue, 01 Feb 2011 11:44:15 +0000</pubDate>
				<category><![CDATA[Advanced programs]]></category>
		<category><![CDATA[C Programs]]></category>
		<category><![CDATA[Binary Search Algorithm]]></category>
		<category><![CDATA[binary search]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=1223</guid>

					<description><![CDATA[<p>#include template int binarySearch(T a[], int n, T&#038; x) { int left = 0; // left end of segment int right = n - 1; // right end of segment while (left a[middle]) left = middle + 1; else right = middle - 1; } return -1; // x not found } int main() {</p>
<p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-advanced/program-to-implement-binary-search-algorithm/">Program to implement Binary Search Algorithm</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<pre lang="cpp">
#include <iostream.h>
template<class T>
int binarySearch(T a[], int n, T& x)
{
	int left = 0;                       // left end of segment
	int right = n - 1;                  // right end of segment
	while (left <= right)
	{
		int middle = (left + right)/2;   // middle of segment
		if (x == a[middle]) return middle;
		if (x > a[middle]) left = middle + 1;
		else right = middle - 1;
	}
	return -1; // x not found
}
int main()
{
	int a[10],n,t;
	cout<<"Enter the size:";
	cin>>n;
	cout<<"enter the elements in sorted order:";
	for(int i=0;i<n;i++)
		cin>>a[i];
	cout<<"enter the element to search:";
	cin>>t;
	int f=binarySearch(a,n,t);
	if(f==-1)
		cout<<"element not found";
	else
		cout<<"element found at index:"<<f;
}
</pre><p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-advanced/program-to-implement-binary-search-algorithm/">Program to implement Binary Search Algorithm</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-advanced/program-to-implement-binary-search-algorithm/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
	</channel>
</rss>
