<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Nitish Kumar&#039;s Blog</title>
	<atom:link href="http://nitishkr.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://nitishkr.wordpress.com</link>
	<description>Crazyyyy  Blogggerrs</description>
	<lastBuildDate>Tue, 24 Jan 2012 19:04:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='nitishkr.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/595768032ec986ad6d4390c86a21d172?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Nitish Kumar&#039;s Blog</title>
		<link>http://nitishkr.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://nitishkr.wordpress.com/osd.xml" title="Nitish Kumar&#039;s Blog" />
	<atom:link rel='hub' href='http://nitishkr.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Write the actual code to parse a regular expression including &#8220;*&#8221;, which stands for 0 or more characters, &#8220;+&#8221;, which stands for 1 or more characters, and &#8220;.&#8221;, which stands for 1 exact character.</title>
		<link>http://nitishkr.wordpress.com/2012/01/02/write-the-actual-code-to-parse-a-regular-expression-including-which-stands-for-0-or-more-characters-which-stands-for-1-or-more-characters-and-which-stands-for-1-exact-character/</link>
		<comments>http://nitishkr.wordpress.com/2012/01/02/write-the-actual-code-to-parse-a-regular-expression-including-which-stands-for-0-or-more-characters-which-stands-for-1-or-more-characters-and-which-stands-for-1-exact-character/#comments</comments>
		<pubDate>Mon, 02 Jan 2012 18:48:04 +0000</pubDate>
		<dc:creator>nitish kumar</dc:creator>
				<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[All]]></category>
		<category><![CDATA[Technical]]></category>

		<guid isPermaLink="false">http://nitishkr.wordpress.com/?p=335</guid>
		<description><![CDATA[#include&#60;iostream&#62; #include&#60;cstring&#62; using namespace std; int m_plus(string a, char c) { if (a[0] != c) return -1; int i=0; while(a[i++] == c); return i-1; } int m_star(string a, char c) { if (a[0] != c) return 0; int i=0; while(a[i++] == c); return i-1; } int m_dot(string a, char c) { if (a[0] != c) [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nitishkr.wordpress.com&amp;blog=8198879&amp;post=335&amp;subd=nitishkr&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>#include&lt;iostream&gt;<br />
#include&lt;cstring&gt;<br />
using namespace std;</p>
<p>int m_plus(string a, char c)<br />
{<br />
if (a[0] != c)<br />
	return -1;<br />
int i=0;<br />
while(a[i++] == c);<br />
return i-1;<br />
}</p>
<p>int m_star(string a, char c)<br />
{<br />
if (a[0] != c)<br />
	return 0;<br />
int i=0;<br />
while(a[i++] == c);<br />
return i-1;<br />
}</p>
<p>int m_dot(string a, char c)<br />
{<br />
if (a[0] != c)<br />
	return -1;<br />
else<br />
	return 1;<br />
}</p>
<p>int main()<br />
{<br />
string s,reg;<br />
int i,j,p;<br />
cin &gt;&gt; reg&gt;&gt;s;</p>
<p>while (reg!=&#8221;" )<br />
{<br />
if (reg.length()&gt;=2)<br />
	{<br />
		if (reg[1] == &#8216;+&#8217;)<br />
			p = m_plus(s,reg[0]);<br />
		else if (reg[1] == &#8216;*&#8217;)<br />
			p = m_star(s,reg[0]);<br />
		else<br />
			p = m_dot(s,reg[0]);<br />
		if ( p == -1)<br />
			{<br />
				cout&lt;&lt;&#8221;Error&#8221;;<br />
				return 0;<br />
			}</p>
<p>		s = s.substr(p,s.length());</p>
<p>		if (reg[1] == &#8216;+&#8217; || reg[1] == &#8216;*&#8217; || reg[1] == &#8216;.&#8217;)</p>
<p>			reg = reg.substr(2,reg.length());<br />
		else<br />
			reg = reg.substr(1,reg.length());<br />
	}<br />
else<br />
	{<br />
	p = m_dot(s,reg[0]);<br />
	if ( p == -1)<br />
			{cout&lt;&lt;&#8221;Error&#8221;;<br />
				return 0;<br />
			}<br />
	s = s.substr(p,s.length());<br />
	reg = reg.substr(1,reg.length());<br />
	}<br />
}</p>
<p>if (s!=&#8221;")<br />
	{cout&lt;&lt;&#8221;Error&#8221;;</p>
<p>         }<br />
else<br />
	cout&lt;&lt;&#8221;Matched&#8221;;<br />
return 0;<br />
}</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nitishkr.wordpress.com/335/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nitishkr.wordpress.com/335/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nitishkr.wordpress.com/335/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nitishkr.wordpress.com/335/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nitishkr.wordpress.com/335/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nitishkr.wordpress.com/335/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nitishkr.wordpress.com/335/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nitishkr.wordpress.com/335/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nitishkr.wordpress.com/335/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nitishkr.wordpress.com/335/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nitishkr.wordpress.com/335/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nitishkr.wordpress.com/335/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nitishkr.wordpress.com/335/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nitishkr.wordpress.com/335/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nitishkr.wordpress.com&amp;blog=8198879&amp;post=335&amp;subd=nitishkr&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nitishkr.wordpress.com/2012/01/02/write-the-actual-code-to-parse-a-regular-expression-including-which-stands-for-0-or-more-characters-which-stands-for-1-or-more-characters-and-which-stands-for-1-exact-character/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fbe0ed876e4db1bb28e775087cd6de0c?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">nitishkr</media:title>
		</media:content>
	</item>
		<item>
		<title>Write a method which finds the maximum of two numbers. You should not use if-else or any other comparison operator. EXAMPLE Input: 5, 10 Output: 10</title>
		<link>http://nitishkr.wordpress.com/2011/12/29/write-a-method-which-finds-the-maximum-of-two-numbers-you-should-not-use-if-else-or-any-other-comparison-operator-example-input-5-10-output-10/</link>
		<comments>http://nitishkr.wordpress.com/2011/12/29/write-a-method-which-finds-the-maximum-of-two-numbers-you-should-not-use-if-else-or-any-other-comparison-operator-example-input-5-10-output-10/#comments</comments>
		<pubDate>Thu, 29 Dec 2011 06:49:33 +0000</pubDate>
		<dc:creator>nitish kumar</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[C Puzzles]]></category>

		<guid isPermaLink="false">http://nitishkr.wordpress.com/?p=332</guid>
		<description><![CDATA[int getMax(int a, int b) { int c = a &#8211; b; int k = (c &#62;&#62; 31) &#38; 0&#215;1; int max = a &#8211; k * c; return max; } if a is smaller , c becomes negetive . thus when right shifting by 31 bits , c becomes 1 and k becomes 1. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nitishkr.wordpress.com&amp;blog=8198879&amp;post=332&amp;subd=nitishkr&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>int getMax(int a, int b) {<br />
int c = a &#8211; b;<br />
int k = (c &gt;&gt; 31) &amp; 0&#215;1;<br />
int max = a &#8211; k * c;<br />
return max;<br />
}</p>
<p>if a is smaller , c becomes negetive . thus when right shifting by 31 bits , c becomes 1 and k becomes 1.<br />
In calculation for max -k * negative c becomes positive assigning b as max value .</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nitishkr.wordpress.com/332/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nitishkr.wordpress.com/332/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nitishkr.wordpress.com/332/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nitishkr.wordpress.com/332/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nitishkr.wordpress.com/332/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nitishkr.wordpress.com/332/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nitishkr.wordpress.com/332/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nitishkr.wordpress.com/332/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nitishkr.wordpress.com/332/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nitishkr.wordpress.com/332/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nitishkr.wordpress.com/332/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nitishkr.wordpress.com/332/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nitishkr.wordpress.com/332/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nitishkr.wordpress.com/332/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nitishkr.wordpress.com&amp;blog=8198879&amp;post=332&amp;subd=nitishkr&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nitishkr.wordpress.com/2011/12/29/write-a-method-which-finds-the-maximum-of-two-numbers-you-should-not-use-if-else-or-any-other-comparison-operator-example-input-5-10-output-10/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fbe0ed876e4db1bb28e775087cd6de0c?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">nitishkr</media:title>
		</media:content>
	</item>
		<item>
		<title>Write an algorithm which computes the number of trailing zeros in n factorial</title>
		<link>http://nitishkr.wordpress.com/2011/12/29/write-an-algorithm-which-computes-the-number-of-trailing-zeros-in-n-factorial/</link>
		<comments>http://nitishkr.wordpress.com/2011/12/29/write-an-algorithm-which-computes-the-number-of-trailing-zeros-in-n-factorial/#comments</comments>
		<pubDate>Thu, 29 Dec 2011 06:38:40 +0000</pubDate>
		<dc:creator>nitish kumar</dc:creator>
				<category><![CDATA[C Puzzles]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[factorial]]></category>

		<guid isPermaLink="false">http://nitishkr.wordpress.com/?p=328</guid>
		<description><![CDATA[Trailing zeros are contributed by pairs of 5 and 2, because 5*2 = 10. To count the number of pairs, we just have to count the number of multiples of 5(as occurence of 2 is more than occurence of 5). While 5 contributes to one multiple of 10, 25 contributes two (because 25 = 5*5). [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nitishkr.wordpress.com&amp;blog=8198879&amp;post=328&amp;subd=nitishkr&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Trailing zeros are contributed by pairs of 5 and 2, because 5*2 = 10. To count the number of<br />
pairs, we just have to count the number of multiples of 5(as occurence of 2 is more than occurence of 5). While 5 contributes to one multiple of 10, 25 contributes two (because 25 = 5*5).</p>
<p>public static int numZeros(int num) {</p>
<p>int count = 0;</p>
<p>if (num &lt; 0) {</p>
<p>System.out.println(“Factorial is not defined for  0; i *= 5) {</p>
<p>count += num / i;</p>
<p>}</p>
<p>return count;<br />
}<br />
Let’s walk through an example to see how this works: Suppose num = 26. In the first loop, we<br />
count how many multiples of five there are by doing 26 / 5 = 5 (these multiples are 5, 10, 15,<br />
20, and 25). In the next loop, we count how many multiples of 25 there are: 26 / 25 = 1 (this<br />
multiple is 25). Thus, we see that we get one zero from 5, 10, 15 and 20, and two zeros from<br />
25 (note how it was counted twice in the loops). Therefore, 26! has six zeros.</p>
<br /> Tagged: <a href='http://nitishkr.wordpress.com/tag/factorial/'>factorial</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nitishkr.wordpress.com/328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nitishkr.wordpress.com/328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nitishkr.wordpress.com/328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nitishkr.wordpress.com/328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nitishkr.wordpress.com/328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nitishkr.wordpress.com/328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nitishkr.wordpress.com/328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nitishkr.wordpress.com/328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nitishkr.wordpress.com/328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nitishkr.wordpress.com/328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nitishkr.wordpress.com/328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nitishkr.wordpress.com/328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nitishkr.wordpress.com/328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nitishkr.wordpress.com/328/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nitishkr.wordpress.com&amp;blog=8198879&amp;post=328&amp;subd=nitishkr&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nitishkr.wordpress.com/2011/12/29/write-an-algorithm-which-computes-the-number-of-trailing-zeros-in-n-factorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fbe0ed876e4db1bb28e775087cd6de0c?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">nitishkr</media:title>
		</media:content>
	</item>
		<item>
		<title>S=max score  individual points p1,p2,&#8230;,pn  how many permutations of p1,&#8230;,pn (multiple occurences of px allowed) give us total score S.  This is essentially based on American football, where each drive can end in 2 points (safety), 3 points (field goal) or 7 points (td+fg).</title>
		<link>http://nitishkr.wordpress.com/2011/12/05/smax-score-individual-points-p1p2-pn-how-many-permutations-of-p1-pn-multiple-occurences-of-px-allowed-give-us-total-score-s-this-is-essentially-based-on-american-football-where-each-d/</link>
		<comments>http://nitishkr.wordpress.com/2011/12/05/smax-score-individual-points-p1p2-pn-how-many-permutations-of-p1-pn-multiple-occurences-of-px-allowed-give-us-total-score-s-this-is-essentially-based-on-american-football-where-each-d/#comments</comments>
		<pubDate>Mon, 05 Dec 2011 05:15:42 +0000</pubDate>
		<dc:creator>nitish kumar</dc:creator>
				<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[All]]></category>
		<category><![CDATA[Technical]]></category>

		<guid isPermaLink="false">http://nitishkr.wordpress.com/?p=299</guid>
		<description><![CDATA[#include&#60;iostream&#62; using namespace std; #define ll long long ll factorial (int x) { ll f = 1; for(int i=2;i&#60;=x; i++) f*= i; return f; } ll count(int c1, int c2, int c3) { ll c = factorial(c1+c2+c3)/ (factorial(c1) * factorial(c2) * factorial(c3)); return c; } int main() { int s = 47, p1= 2, p2 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nitishkr.wordpress.com&amp;blog=8198879&amp;post=299&amp;subd=nitishkr&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>#include&lt;iostream&gt;<br />
using namespace std;<br />
#define ll long long </p>
<p>ll factorial (int x)<br />
{<br />
ll f = 1;<br />
for(int i=2;i&lt;=x; i++)<br />
f*= i;<br />
return f;<br />
}</p>
<p>ll count(int c1, int c2, int c3)<br />
{<br />
ll c = factorial(c1+c2+c3)/ (factorial(c1) * factorial(c2) * factorial(c3));<br />
return c;<br />
}</p>
<p>int main()<br />
{</p>
<p>int s = 47, p1= 2, p2 = 3, p3 = 7;</p>
<p>int m1,m2,m3;</p>
<p>int i,j,k;<br />
ll c= 0;<br />
cout&lt;&lt;s/p2&lt;&lt;endl;<br />
for(i=0;i&lt;=s/p1;i++)<br />
for(j=0;j&lt;=s/p2;j++)<br />
for(k=0;k&lt;=s/p3; k++)<br />
if (i * p1 + j * p2 + k*p3 == s)<br />
	{<br />
		//cout&lt;&lt;i&lt;&lt;&#8221; &#8220;&lt;&lt;j&lt;&lt;&#8221; &#8220;&lt;&lt;k&lt;&lt;endl;<br />
		c += count(i,j,k);<br />
	}<br />
cout&lt;&lt;c&lt;&lt;endl;<br />
return 0;<br />
}</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nitishkr.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nitishkr.wordpress.com/299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nitishkr.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nitishkr.wordpress.com/299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nitishkr.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nitishkr.wordpress.com/299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nitishkr.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nitishkr.wordpress.com/299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nitishkr.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nitishkr.wordpress.com/299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nitishkr.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nitishkr.wordpress.com/299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nitishkr.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nitishkr.wordpress.com/299/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nitishkr.wordpress.com&amp;blog=8198879&amp;post=299&amp;subd=nitishkr&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nitishkr.wordpress.com/2011/12/05/smax-score-individual-points-p1p2-pn-how-many-permutations-of-p1-pn-multiple-occurences-of-px-allowed-give-us-total-score-s-this-is-essentially-based-on-american-football-where-each-d/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fbe0ed876e4db1bb28e775087cd6de0c?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">nitishkr</media:title>
		</media:content>
	</item>
		<item>
		<title>Find the min and max in an array. Now do it in less than 2n comparisons. (they were looking for the solution that finds both max and min in about 3/2 n comparisons).</title>
		<link>http://nitishkr.wordpress.com/2011/12/05/find-the-min-and-max-in-an-array-now-do-it-in-less-than-2n-comparisons-they-were-looking-for-the-solution-that-finds-both-max-and-min-in-about-32-n-comparisons/</link>
		<comments>http://nitishkr.wordpress.com/2011/12/05/find-the-min-and-max-in-an-array-now-do-it-in-less-than-2n-comparisons-they-were-looking-for-the-solution-that-finds-both-max-and-min-in-about-32-n-comparisons/#comments</comments>
		<pubDate>Mon, 05 Dec 2011 04:31:49 +0000</pubDate>
		<dc:creator>nitish kumar</dc:creator>
				<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[All]]></category>
		<category><![CDATA[Technical]]></category>

		<guid isPermaLink="false">http://nitishkr.wordpress.com/?p=297</guid>
		<description><![CDATA[#include&#60;iostream&#62; #include&#60;vector&#62; #include &#60;algorithm&#62; using namespace std; int main() { vector&#60;int&#62; maxi,mini; int a[10] = {3,2,1,0,9,4,-1,6,8,9}; int i,s,m; for ( i=0; i&#60;9; i+=2) // n/2 comparisons { s = a[i]+a[i+1]; m = max(a[i],a[i+1]); maxi.push_back(m); mini.push_back(s-m); } cout&#60;&#60;*max_element(maxi.begin(), maxi.end())&#60;&#60;endl; // n/2 comparisons ;cout&#60;&#60;*min_element(mini.begin(), mini.end())&#60;&#60;endl; // n/2 comparisons return 0; }<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nitishkr.wordpress.com&amp;blog=8198879&amp;post=297&amp;subd=nitishkr&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>#include&lt;iostream&gt;<br />
#include&lt;vector&gt;<br />
#include &lt;algorithm&gt;</p>
<p>using namespace std;</p>
<p>int main()<br />
{<br />
vector&lt;int&gt; maxi,mini;</p>
<p>int a[10] = {3,2,1,0,9,4,-1,6,8,9};<br />
int i,s,m;</p>
<p>for ( i=0; i&lt;9; i+=2)				// n/2 comparisons<br />
{<br />
 s = a[i]+a[i+1];<br />
m = max(a[i],a[i+1]);<br />
maxi.push_back(m);<br />
mini.push_back(s-m);</p>
<p>}</p>
<p>cout&lt;&lt;*max_element(maxi.begin(), maxi.end())&lt;&lt;endl;		// n/2 comparisons<br />
;cout&lt;&lt;*min_element(mini.begin(), mini.end())&lt;&lt;endl;		// n/2 comparisons</p>
<p>return 0;<br />
}</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nitishkr.wordpress.com/297/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nitishkr.wordpress.com/297/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nitishkr.wordpress.com/297/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nitishkr.wordpress.com/297/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nitishkr.wordpress.com/297/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nitishkr.wordpress.com/297/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nitishkr.wordpress.com/297/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nitishkr.wordpress.com/297/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nitishkr.wordpress.com/297/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nitishkr.wordpress.com/297/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nitishkr.wordpress.com/297/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nitishkr.wordpress.com/297/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nitishkr.wordpress.com/297/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nitishkr.wordpress.com/297/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nitishkr.wordpress.com&amp;blog=8198879&amp;post=297&amp;subd=nitishkr&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nitishkr.wordpress.com/2011/12/05/find-the-min-and-max-in-an-array-now-do-it-in-less-than-2n-comparisons-they-were-looking-for-the-solution-that-finds-both-max-and-min-in-about-32-n-comparisons/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fbe0ed876e4db1bb28e775087cd6de0c?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">nitishkr</media:title>
		</media:content>
	</item>
		<item>
		<title>FInd the maximum sum of a sub-sequence from an positive integer array where any two numbers of sub-sequence are not adjacent to each other in the original sequence. E.g 1 2 3 4 5 6 &#8211;&gt; 2 4 6</title>
		<link>http://nitishkr.wordpress.com/2011/12/05/find-the-maximum-sum-of-a-sub-sequence-from-an-positive-integer-array-where-any-two-numbers-of-sub-sequence-are-not-adjacent-to-each-other-in-the-original-sequence-e-g-1-2-3-4-5-6-2-4-6/</link>
		<comments>http://nitishkr.wordpress.com/2011/12/05/find-the-maximum-sum-of-a-sub-sequence-from-an-positive-integer-array-where-any-two-numbers-of-sub-sequence-are-not-adjacent-to-each-other-in-the-original-sequence-e-g-1-2-3-4-5-6-2-4-6/#comments</comments>
		<pubDate>Mon, 05 Dec 2011 04:15:28 +0000</pubDate>
		<dc:creator>nitish kumar</dc:creator>
				<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[All]]></category>
		<category><![CDATA[Technical]]></category>

		<guid isPermaLink="false">http://nitishkr.wordpress.com/?p=295</guid>
		<description><![CDATA[#include&#60;iostream&#62; #include&#60;algorithm&#62; using namespace std; int main() { int a[100]={0},n; int i; int maxy[10]={0}; cout&#60;&#60;&#8221;\nEnter number of elements in array&#8221;; cin &#62;&#62; n; for(i=0; i&#60;n;i++) cin &#62;&#62; a[i]; for(i=n-1; i&#62;=0 ; i&#8211;) maxy[i] = a[i] +max( maxy[i+2],maxy[i+3]); cout&#60;&#60;max(maxy[0], maxy[1]); return 0; }<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nitishkr.wordpress.com&amp;blog=8198879&amp;post=295&amp;subd=nitishkr&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>#include&lt;iostream&gt;<br />
#include&lt;algorithm&gt;</p>
<p>using namespace std;</p>
<p>int main()<br />
{<br />
int a[100]={0},n;<br />
int i;<br />
int maxy[10]={0};<br />
cout&lt;&lt;&#8221;\nEnter number of elements in array&#8221;;<br />
cin &gt;&gt; n;<br />
for(i=0; i&lt;n;i++)<br />
cin &gt;&gt; a[i];</p>
<p>for(i=n-1; i&gt;=0 ; i&#8211;)<br />
maxy[i] = a[i] +max( maxy[i+2],maxy[i+3]);</p>
<p>cout&lt;&lt;max(maxy[0], maxy[1]);<br />
return 0;<br />
}</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nitishkr.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nitishkr.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nitishkr.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nitishkr.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nitishkr.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nitishkr.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nitishkr.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nitishkr.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nitishkr.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nitishkr.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nitishkr.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nitishkr.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nitishkr.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nitishkr.wordpress.com/295/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nitishkr.wordpress.com&amp;blog=8198879&amp;post=295&amp;subd=nitishkr&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nitishkr.wordpress.com/2011/12/05/find-the-maximum-sum-of-a-sub-sequence-from-an-positive-integer-array-where-any-two-numbers-of-sub-sequence-are-not-adjacent-to-each-other-in-the-original-sequence-e-g-1-2-3-4-5-6-2-4-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fbe0ed876e4db1bb28e775087cd6de0c?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">nitishkr</media:title>
		</media:content>
	</item>
		<item>
		<title>Snake Game in Opengl in C</title>
		<link>http://nitishkr.wordpress.com/2011/11/04/snake-game-in-opengl-in-c/</link>
		<comments>http://nitishkr.wordpress.com/2011/11/04/snake-game-in-opengl-in-c/#comments</comments>
		<pubDate>Fri, 04 Nov 2011 16:03:43 +0000</pubDate>
		<dc:creator>nitish kumar</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[download opengl project]]></category>
		<category><![CDATA[snake game]]></category>
		<category><![CDATA[snake game in opengl]]></category>

		<guid isPermaLink="false">http://nitishkr.wordpress.com/?p=286</guid>
		<description><![CDATA[Hi everyone , In this blogpost I would like to share my OpenGl game project which I had developed for my semester course on Computer Graphics . It took almost a week to complete this project . Project Description The project&#8217;s aim was to create a 2d snake game . This snake keeps on growing [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nitishkr.wordpress.com&amp;blog=8198879&amp;post=286&amp;subd=nitishkr&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div id="attachment_285" class="wp-caption aligncenter" style="width: 650px"><a href="http://nitishkr.files.wordpress.com/2011/11/snake2.png"><img src="http://nitishkr.files.wordpress.com/2011/11/snake2.png?w=640&#038;h=400" alt="" title="Snake Level Kobra" width="640" height="400" class="size-full wp-image-285" /></a><p class="wp-caption-text">Snake</p></div>
<p>Hi everyone ,<br />
     In this blogpost I would like to share my OpenGl game project which I had developed for my semester course on Computer Graphics . It took almost a week to complete this project . </p>
<p><strong>Project Description </strong></p>
<p>The project&#8217;s aim  was to create a 2d snake game . This snake keeps on growing with the consumption of fruit . The game ends with the snake either colliding with itself or with the blocks . The game has a number of features associated with it like specular lighting effect, score and high score, play/pause the game and 3 exciting game levels :- worm, snake and kobra . </p>
<p><strong>Keys </strong></p>
<p>Up            &#8211;  moves up<br />
Down          &#8211;  moves down<br />
Left          &#8211;  moves left<br />
Right         &#8211;  moves right<br />
p/P           &#8211;  pauses game<br />
any other key &#8211;  resumes game</p>
<p><strong>Platform </strong> :- Linux / Ubuntu</p>
<p><strong>How to Run</strong><br />
 Change the .doc extension to .zip<br />
 Unzip the file<br />
 run the file using ./snake in the terminal<br />
 compile the files using gl -o snake *.cpp</p>
<p>Source code can be downloaded  from here :- <a href='http://nitishkr.files.wordpress.com/2011/11/snake.doc'>snake</a></p>
<br /> Tagged: <a href='http://nitishkr.wordpress.com/tag/download-opengl-project/'>download opengl project</a>, <a href='http://nitishkr.wordpress.com/tag/snake-game/'>snake game</a>, <a href='http://nitishkr.wordpress.com/tag/snake-game-in-opengl/'>snake game in opengl</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nitishkr.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nitishkr.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nitishkr.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nitishkr.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nitishkr.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nitishkr.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nitishkr.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nitishkr.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nitishkr.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nitishkr.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nitishkr.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nitishkr.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nitishkr.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nitishkr.wordpress.com/286/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nitishkr.wordpress.com&amp;blog=8198879&amp;post=286&amp;subd=nitishkr&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nitishkr.wordpress.com/2011/11/04/snake-game-in-opengl-in-c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fbe0ed876e4db1bb28e775087cd6de0c?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">nitishkr</media:title>
		</media:content>

		<media:content url="http://nitishkr.files.wordpress.com/2011/11/snake2.png" medium="image">
			<media:title type="html">Snake Level Kobra</media:title>
		</media:content>
	</item>
		<item>
		<title>Predict the output</title>
		<link>http://nitishkr.wordpress.com/2011/08/30/predict-the-output/</link>
		<comments>http://nitishkr.wordpress.com/2011/08/30/predict-the-output/#comments</comments>
		<pubDate>Tue, 30 Aug 2011 05:50:16 +0000</pubDate>
		<dc:creator>nitish kumar</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[C Puzzles]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[fork]]></category>

		<guid isPermaLink="false">http://nitishkr.wordpress.com/?p=277</guid>
		<description><![CDATA[#include #include main() { int ret; ret = fork(); ret = fork(); ret = fork(); ret = fork(); if(!ret) printf(&#8220;zero\n&#8221;); else printf(&#8220;one\n&#8221;); } fork creates a child process. So, 2^4 times the if statement gets executed out of which 8 are ones and other 8 are zero&#8217;s. The order of output is compiler dependent. Tagged: [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nitishkr.wordpress.com&amp;blog=8198879&amp;post=277&amp;subd=nitishkr&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>#include<br />
#include</p>
<p>main()<br />
{<br />
  int ret;<br />
  ret = fork();<br />
  ret = fork();<br />
  ret = fork();<br />
  ret = fork();</p>
<p>  if(!ret)<br />
   printf(&#8220;zero\n&#8221;);<br />
  else<br />
   printf(&#8220;one\n&#8221;);</p>
<p>}</p>
<p>fork creates  a child process. So, 2^4 times the if statement gets executed out of which 8 are ones and other 8 are zero&#8217;s. The order of output is compiler dependent. </p>
<br /> Tagged: <a href='http://nitishkr.wordpress.com/tag/fork/'>fork</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nitishkr.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nitishkr.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nitishkr.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nitishkr.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nitishkr.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nitishkr.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nitishkr.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nitishkr.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nitishkr.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nitishkr.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nitishkr.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nitishkr.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nitishkr.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nitishkr.wordpress.com/277/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nitishkr.wordpress.com&amp;blog=8198879&amp;post=277&amp;subd=nitishkr&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nitishkr.wordpress.com/2011/08/30/predict-the-output/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fbe0ed876e4db1bb28e775087cd6de0c?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">nitishkr</media:title>
		</media:content>
	</item>
		<item>
		<title>Linked List Implementation</title>
		<link>http://nitishkr.wordpress.com/2011/08/30/linked-list-implementation/</link>
		<comments>http://nitishkr.wordpress.com/2011/08/30/linked-list-implementation/#comments</comments>
		<pubDate>Tue, 30 Aug 2011 05:30:53 +0000</pubDate>
		<dc:creator>nitish kumar</dc:creator>
				<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[All]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[Linked List]]></category>

		<guid isPermaLink="false">http://nitishkr.wordpress.com/?p=274</guid>
		<description><![CDATA[/* PROGRAM IMPLEMENTATION OF SINGLE LINKED LIST */ #include&#60;stdio.h&#62; #include&#60;stdlib.h&#62; //#define NULL 0 /* STRUCTURE CONTANING A DATA PART AND A LINK PART */ struct node { int data; struct node *next; }*p; /* P IS A GLOBAL POINTER CONTAINS THE ADRESS OF THE FIRST NODE IN LIST */ /*THIS FUNCTION DELETES A NODE */ [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nitishkr.wordpress.com&amp;blog=8198879&amp;post=274&amp;subd=nitishkr&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>     /* PROGRAM IMPLEMENTATION OF SINGLE LINKED LIST */</p>
<p>#include&lt;stdio.h&gt;<br />
#include&lt;stdlib.h&gt;<br />
  //#define NULL 0<br />
  /* STRUCTURE CONTANING A DATA PART AND A LINK PART */</p>
<p>   struct node<br />
 {<br />
   int data;<br />
   struct node *next;<br />
 }*p;</p>
<p>  /* P IS A GLOBAL POINTER CONTAINS THE ADRESS OF THE FIRST NODE IN<br />
LIST<br />
*/</p>
<p> /*THIS FUNCTION DELETES A NODE */</p>
<p>    void  delnode(int num)<br />
 {<br />
     struct node *temp, *m;<br />
temp=p;<br />
      while(temp!=NULL)<br />
    {<br />
       if(temp-&gt;data==num)<br />
       {<br />
           if(temp==p)<br />
           {<br />
              p=temp-&gt;next;<br />
              free(temp);<br />
              return;<br />
           }<br />
           else<br />
         {<br />
           m-&gt;next=temp-&gt;next;<br />
           free(temp);<br />
           return;<br />
         }<br />
      }else<br />
        {<br />
           m=temp;<br />
          temp= temp-&gt;next;<br />
        }</p>
<p>}<br />
    printf(&#8221; ELEMENT %d NOT FOUND &#8220;, num);<br />
}/*THIS FUNCTION ADDS A NODE AT THE LAST OF LINKED LIST */</p>
<p>   void append( int num )<br />
 {<br />
     struct node *temp,*r;<br />
     /* CREATING A NODE AND ASSIGNING A VALUE TO IT */</p>
<p>       temp= (struct node *)malloc(sizeof(struct node));<br />
       temp-&gt;data=num;<br />
       r=p;</p>
<p>      if (p == NULL) /* IF LIST IS EMPTY CREATE FIRST NODE */<br />
     {<br />
    p=temp;<br />
         p-&gt;next =NULL;<br />
     }<br />
  else<br />
     {        /* GO TO LAST AND ADD*/</p>
<p>             while( r-&gt;next != NULL)<br />
       r=r-&gt;next;<br />
       r-&gt;next =temp;<br />
       r=temp;<br />
       r-&gt;next=NULL;<br />
     }<br />
  }/* ADD A NEW NODE AT BEGINNING  */</p>
<p>       addbeg( int num )<br />
   {<br />
        /*  CREATING A NODE AND INSERTING VALUE TO IT  */</p>
<p>   struct node *temp;<br />
        temp=(struct node *)malloc(sizeof(struct node));<br />
        temp-&gt;data=num;</p>
<p>       /* IF LIST IS NULL ADD AT BEGINNING  */<br />
        if ( p== NULL)<br />
       {<br />
          p=temp;<br />
          p-&gt;next=NULL;<br />
       }</p>
<p>   else<br />
      {<br />
          temp-&gt;next=p;<br />
          p=temp;<br />
      }<br />
   }</p>
<p> /*  ADD A NEW NODE AFTER A SPECIFIED NO OF NODES */</p>
<p> addafter(int num, int loc)<br />
  {<br />
     int i;<br />
     struct node *temp,*t,*r;<br />
     r=p;       /* here r stores the first location */<br />
      if(loc &gt; count() + 1 || loc &lt;= 0)<br />
   {<br />
         printf(&#8221; insertion is not possible : &#8220;);<br />
            return;<br />
   }<br />
        if (loc == 1)/* if list is null then add at beginning */<br />
         {<br />
           addbeg(num);<br />
           return;<br />
         }<br />
      else<br />
 {<br />
       for(i=1;i&lt;loc;i++)<br />
          {<br />
             t=r;   /* t will be holding previous value */<br />
             r=r-&gt;next;<br />
          }<br />
         temp=(struct node *)malloc(sizeof(struct node));<br />
         temp-&gt;data=num;<br />
         t-&gt;next=temp;<br />
         t=temp;<br />
         t-&gt;next=r;<br />
        return;<br />
       }<br />
}/* THIS FUNCTION DISPLAYS THE CONTENTS OF THE LINKED LIST */</p>
<p>  display(struct node *r)<br />
  {<br />
      r=p;<br />
      if(r==NULL)<br />
     {<br />
       printf(&#8220;NO ELEMENT IN THE LIST :&#8221;);<br />
       return;<br />
     }<br />
       /* traverse the entire linked list */<br />
       while(r!=NULL)<br />
    {<br />
      printf(&#8221; -&gt; %d &#8220;,r-&gt;data);<br />
      r=r-&gt;next;<br />
    }<br />
     printf(&#8220;&#8221;);<br />
  }<br />
//THIS FUNCTION COUNTS THE NUMBER OF ELEMENTS IN THE LIST<br />
count()<br />
 {<br />
   struct node *n;<br />
   int c=0;<br />
   n=p;<br />
    while(n!=NULL)<br />
   {<br />
     n=n-&gt;next;<br />
     c++;<br />
   }<br />
  return(c);<br />
 }<br />
//THIS FUNCTION REVERSES A LINKED LIST<br />
reverse(struct node *q)<br />
{<br />
   struct node *m, *n,*l,*s;<br />
   m=q;<br />
   n=NULL;<br />
  while(m!=NULL)<br />
 {<br />
   s=n;<br />
   n=m;<br />
  m=m-&gt;next;<br />
  n-&gt;next=s;<br />
 }<br />
   p=n;<br />
}</p>
<p>/* THIS IS THE MAIN PROGRAM  */</p>
<p>  main()<br />
 {<br />
        int i;<br />
   p=NULL;<br />
   while(1) /* this is an indefinite loop */<br />
 {<br />
    printf(&#8220;\n1.INSERT A NUMBER AT BEGINNING;\n&#8221;);<br />
    printf(&#8221; 2.INSERT A NUMBER AT LAST:\n&#8221;);<br />
    printf(&#8221; 3.INSERT A NUMBER AT A PARTICULAR LOCATION INlIST:\n&#8221;);<br />
    printf(&#8221; 4.PRINT THE ELEMENTS IN THE LIST :\n&#8221;);<br />
    printf(&#8221; 5.PRINT THE NUMBER OF ELEMENTS IN THE LIST\n&#8221;);<br />
    printf(&#8221; 6.DELETE A NODE IN THE LINKED LIST:\n&#8221;);<br />
    printf(&#8221; 7.REVERSE A LINKED LIST :\n&#8221;);<br />
    printf(&#8221; 8.GET OUT OF LINKED LIST (BYEE BYEE):\n&#8221;);<br />
    printf(&#8221; PLEASE, ENTER THE NUMBER:\n&#8221;);</p>
<p>    scanf(&#8220;%d&#8221;,&amp;i); /* ENTER A VALUE FOR SWITCH  */</p>
<p>      switch(i)<br />
    {<br />
         case 1:<br />
      {<br />
        int num;<br />
        printf(&#8221; PLEASE ENTER THE NUMBER :-&#8221;);<br />
        scanf(&#8220;%d&#8221;,&amp;num);<br />
        addbeg(num);<br />
        break;<br />
      }<br />
          case 2:<br />
       {<br />
         int num;<br />
         printf(&#8221; PLEASE ENTER THE NUMBER :-&#8221;);<br />
         scanf(&#8220;%d&#8221;,&amp;num);<br />
         append(num);<br />
         break;<br />
       }</p>
<p>   case 3:<br />
     {<br />
      int num, loc,k;<br />
      printf(&#8221; PLEASE ENTER THE NUMBER :-&#8221;);<br />
      scanf(&#8220;%d&#8221;,&amp;num);<br />
      printf(&#8220;PLEASE ENTER THE LOCATION NUMBER :-&#8221;);<br />
      scanf(&#8220;%d&#8221;,&amp;loc);<br />
      addafter(num,loc);<br />
      break;<br />
    }  case 4:<br />
      {<br />
         struct node *n;<br />
         printf(&#8221;   THE  ELEMENTS IN THE LIST ARE : &#8220;);<br />
         display(n);<br />
         break;<br />
      }</p>
<p>      case 5:<br />
   {<br />
      struct node *n;<br />
      //display(n);<br />
      printf(&#8221; TOTAL NO OF ELEMENTS IN THE LSIT ARE %d&#8221;,count());<br />
      break;<br />
   } case 6:<br />
    {<br />
            int    num;<br />
      printf(&#8221; PLEASE ENTER A NUMBER FROM THE LIST :&#8221;);<br />
      scanf(&#8220;%d&#8221;,&amp;num);<br />
      delnode(num);<br />
     break;<br />
    }<br />
   case 7:<br />
    {<br />
      reverse(p);<br />
        //display(p);<br />
        break;<br />
    }<br />
  case 8:<br />
 {<br />
  exit(1);<br />
 }<br />
    }/* end if switch */<br />
 }/* end of while */<br />
}/* end of main */</p>
<br /> Tagged: <a href='http://nitishkr.wordpress.com/tag/linked-list/'>Linked List</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nitishkr.wordpress.com/274/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nitishkr.wordpress.com/274/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nitishkr.wordpress.com/274/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nitishkr.wordpress.com/274/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nitishkr.wordpress.com/274/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nitishkr.wordpress.com/274/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nitishkr.wordpress.com/274/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nitishkr.wordpress.com/274/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nitishkr.wordpress.com/274/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nitishkr.wordpress.com/274/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nitishkr.wordpress.com/274/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nitishkr.wordpress.com/274/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nitishkr.wordpress.com/274/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nitishkr.wordpress.com/274/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nitishkr.wordpress.com&amp;blog=8198879&amp;post=274&amp;subd=nitishkr&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nitishkr.wordpress.com/2011/08/30/linked-list-implementation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fbe0ed876e4db1bb28e775087cd6de0c?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">nitishkr</media:title>
		</media:content>
	</item>
		<item>
		<title>Binary Search Tree Implementation</title>
		<link>http://nitishkr.wordpress.com/2011/08/30/binary-search-tree-implementation/</link>
		<comments>http://nitishkr.wordpress.com/2011/08/30/binary-search-tree-implementation/#comments</comments>
		<pubDate>Tue, 30 Aug 2011 05:22:20 +0000</pubDate>
		<dc:creator>nitish kumar</dc:creator>
				<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[All]]></category>
		<category><![CDATA[bst]]></category>
		<category><![CDATA[insert]]></category>

		<guid isPermaLink="false">http://nitishkr.wordpress.com/?p=270</guid>
		<description><![CDATA[Following is the implementation of a binary search tree along with functions of Insert, Inorder traversal, Count of no of leaf, Level of a particular Number,Find the subnode, Print element at the same level . #include&#60;stdio.h&#62; #include&#60;stdlib.h&#62; int nol=0,non=0; struct tree { int no; struct tree *l,*r; }; struct tree *root=NULL; struct tree * search(int [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nitishkr.wordpress.com&amp;blog=8198879&amp;post=270&amp;subd=nitishkr&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Following is the implementation of a binary search tree along with functions of Insert, Inorder  traversal, Count of no of leaf,  Level of a particular Number,Find the subnode, Print element at the same level .</p>
<p>#include&lt;stdio.h&gt;<br />
#include&lt;stdlib.h&gt;</p>
<p>int nol=0,non=0;</p>
<p>struct tree<br />
{<br />
int no;<br />
struct tree *l,*r;<br />
};</p>
<p>struct tree *root=NULL;</p>
<p>struct tree * search(int val,int *found)<br />
{<br />
struct tree *p=root,*par=NULL;<br />
while(p!=NULL)<br />
{<br />
if(val==p-&gt;no)<br />
{<br />
*found=1;<br />
break;<br />
}<br />
else if(val &gt; p-&gt;no)<br />
{<br />
par=p;<br />
p=p-&gt;r;<br />
}<br />
else<br />
{<br />
par=p;<br />
p=p-&gt;l;<br />
}<br />
}<br />
return par;<br />
}</p>
<p>void insert(int val)<br />
{<br />
int f=0;<br />
struct tree *n,*parent;<br />
n=(struct tree*)malloc(sizeof(struct tree));<br />
n-&gt;no=val;<br />
n-&gt;l=n-&gt;r=NULL;<br />
if (root==NULL)<br />
{<br />
root=n;<br />
return;<br />
}<br />
parent=search(val ,&amp;f);<br />
if(f==1)<br />
{<br />
printf(&#8220;\n\n\n DUPlicate number&#8221;);<br />
free(n);<br />
return;<br />
}</p>
<p>else if(val&gt;parent-&gt;no)<br />
parent-&gt;r=n;<br />
else<br />
parent-&gt;l=n;<br />
}</p>
<p>void countnoofleaf(struct tree *p)<br />
{<br />
if(p!=NULL)<br />
{<br />
if((p-&gt;l==NULL)&amp;&amp;(p-&gt;r==NULL))<br />
nol++;<br />
else<br />
countnoofleaf(p-&gt;l);<br />
countnoofleaf(p-&gt;r);<br />
}<br />
}</p>
<p>int level(struct tree *p,int val)<br />
{<br />
int f=0;<br />
search(val,&amp;f);<br />
if(f==1)<br />
{<br />
while(val!=p-&gt;no)<br />
{<br />
if(val&gt;p-&gt;no)<br />
{<br />
p=p-&gt;r;<br />
nol++;<br />
}<br />
else<br />
{<br />
p=p-&gt;l;<br />
nol++;<br />
}<br />
}<br />
return nol;<br />
}<br />
else<br />
{<br />
printf(&#8220;\n\nThe Number u entered is not Available&#8221;);<br />
return -1;<br />
}<br />
}</p>
<p>void inorder(struct tree *p)<br />
{<br />
if(p!=NULL)<br />
{<br />
inorder(p-&gt;l);<br />
printf(&#8221; %d&#8221;,p-&gt;no);<br />
inorder(p-&gt;r);<br />
}<br />
}</p>
<p>void countnode(struct tree *p )<br />
{<br />
if(p!=NULL)<br />
{<br />
if(p-&gt;l!=NULL)<br />
{<br />
non++;<br />
countnode(p-&gt;l);<br />
}<br />
if(p-&gt;r!=NULL)<br />
{non++;<br />
countnode(p-&gt;r);<br />
}<br />
}<br />
}</p>
<p>void countsubnode(struct tree *p,int val)<br />
{<br />
int f=0;<br />
search(val,&amp;f);<br />
if(f==1)<br />
{<br />
while(val!=p-&gt;no)<br />
{<br />
if(val&gt;p-&gt;no)<br />
{<br />
p=p-&gt;r;<br />
}<br />
else<br />
p=p-&gt;l;<br />
}<br />
countnode(p);<br />
}<br />
}</p>
<p>void plevelno(struct tree *p,int lvl)<br />
{ int i=0;<br />
if(p!=NULL)<br />
{<br />
i=level(root,p-&gt;no);<br />
nol=0;</p>
<p>if(i==lvl)<br />
printf(&#8220;\n %d&#8221;,p-&gt;no);<br />
else<br />
plevelno(p-&gt;l,lvl);<br />
plevelno(p-&gt;r,lvl);<br />
}<br />
}</p>
<p>void main()<br />
{</p>
<p>int val,ch,i;<br />
do<br />
{<br />
printf(&#8220;\n\n\n 1 To Insert&#8221;);<br />
printf(&#8220;\n 2 To INORDER traversing of TREE&#8221;);<br />
printf(&#8220;\n 3 To Count no of leaf&#8221;);<br />
printf(&#8220;\n 4 To Find The LEVEL of a particular NUMber&#8221;);<br />
printf(&#8220;\n 5 To find the subnode&#8221;);<br />
printf(&#8220;\n 6 To print element of the same LEVEL&#8221;);<br />
printf(&#8220;\n Enter ur choice&#8221;);<br />
scanf(&#8220;%d&#8221;,&amp;ch);</p>
<p>switch(ch)<br />
{<br />
case 1:printf(&#8220;\n\n Enter NUMBER&#8221;);<br />
scanf(&#8220;%d&#8221;,&amp;val);<br />
insert( val);<br />
break;<br />
case 2: inorder(root);<br />
break;<br />
case 3: countnoofleaf(root);<br />
printf(&#8220;\n\n Number of Leaf is %d&#8221;,nol);<br />
nol=0;<br />
break;<br />
case 4: printf(&#8220;\n\n Enter the number&#8221;);<br />
scanf(&#8220;%d&#8221;,&amp;val);<br />
i=level(root,val);<br />
if(i!=-1)<br />
printf(&#8220;\n\n The level of %d is %d&#8221;,val,i);<br />
nol=0;<br />
break;<br />
case 5: printf(&#8220;\n\n Enter the NUMBER&#8221;);<br />
scanf(&#8220;%d&#8221;,&amp;val);<br />
countsubnode(root,val);<br />
printf(&#8220;\n\nNumber of subnode is %d&#8221;,non);<br />
non=0;<br />
break;<br />
case 6: printf(&#8220;\n\n Enter the LEVEL no.&#8221;);<br />
scanf(&#8220;%d&#8221;,&amp;val);<br />
plevelno(root,val);<br />
break;<br />
case 0: break;<br />
default:printf(&#8220;\n\nInvalid Choice&#8221;);<br />
}<br />
}while(ch!=0) ;</p>
<p>}</p>
<br /> Tagged: <a href='http://nitishkr.wordpress.com/tag/bst/'>bst</a>, <a href='http://nitishkr.wordpress.com/tag/insert/'>insert</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nitishkr.wordpress.com/270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nitishkr.wordpress.com/270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nitishkr.wordpress.com/270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nitishkr.wordpress.com/270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nitishkr.wordpress.com/270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nitishkr.wordpress.com/270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nitishkr.wordpress.com/270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nitishkr.wordpress.com/270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nitishkr.wordpress.com/270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nitishkr.wordpress.com/270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nitishkr.wordpress.com/270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nitishkr.wordpress.com/270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nitishkr.wordpress.com/270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nitishkr.wordpress.com/270/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nitishkr.wordpress.com&amp;blog=8198879&amp;post=270&amp;subd=nitishkr&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nitishkr.wordpress.com/2011/08/30/binary-search-tree-implementation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fbe0ed876e4db1bb28e775087cd6de0c?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">nitishkr</media:title>
		</media:content>
	</item>
	</channel>
</rss>
