<?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>In the back of my mind</title>
	<atom:link href="http://sinea.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://sinea.wordpress.com</link>
	<description>I see something there     ~..~</description>
	<lastBuildDate>Sun, 07 Jun 2009 08:34:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='sinea.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>In the back of my mind</title>
		<link>http://sinea.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://sinea.wordpress.com/osd.xml" title="In the back of my mind" />
	<atom:link rel='hub' href='http://sinea.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Lychrel Numbers</title>
		<link>http://sinea.wordpress.com/2009/06/07/lychrel-numbers/</link>
		<comments>http://sinea.wordpress.com/2009/06/07/lychrel-numbers/#comments</comments>
		<pubDate>Sun, 07 Jun 2009 08:34:44 +0000</pubDate>
		<dc:creator>sinea</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[computing]]></category>
		<category><![CDATA[ducky]]></category>
		<category><![CDATA[large numbers]]></category>
		<category><![CDATA[Lychrel]]></category>
		<category><![CDATA[math]]></category>

		<guid isPermaLink="false">http://sinea.wordpress.com/?p=44</guid>
		<description><![CDATA[#include &#60;iostream&#62; #include &#60;fstream&#62; using namespace std; bool isPoli(int* arr, int length) { for(int i=0; i&#60;length/2; i++) if(arr[i] != arr[length-i-1]) return false; return true; } bool isLishel(int* numArray, int length, int depth) { /* IF I REACH DEPTH OF 100 JUST LEAVE IT &#8230;  * &#8230; CAN CHANGE TO ANY DEPTH &#8230; JUST NEED  * [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sinea.wordpress.com&amp;blog=7696586&amp;post=44&amp;subd=sinea&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">#include &lt;iostream&gt;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">#include &lt;fstream&gt;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">using namespace std;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">bool isPoli(int* arr, int length)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>for(int i=0; i&lt;length/2; i++)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>if(arr[i] != arr[length-i-1])</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return false;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return true;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">bool isLishel(int* numArray, int length, int depth)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>/* IF I REACH DEPTH OF 100 JUST LEAVE IT &#8230; </div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span> * &#8230; CAN CHANGE TO ANY DEPTH &#8230; JUST NEED </div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span> * TO HAVE VERY FAST CPU</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span> */</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>if(++depth == 100) return false;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>int rest = 0;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>int *fin = new int[length+1];</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>for(int i = 0 ; i &lt; length; i ++)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>fin[i] = (numArray[i]+numArray[length-i-1]+rest)%10;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>rest = (numArray[i]+numArray[length-i-1]+rest)/10;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>int l = length;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>if(rest != 0)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>l++;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>fin[length] = rest;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span></div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>if(isPoli(fin, l))</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return true;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>if(isLishel(fin, l, depth))</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return true;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return false;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">int main()</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>int num, *arr;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>int num2 = 0;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>int length = 0;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>arr = new int[30];</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>int *pre = new int[32768];</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>int idx = 0;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>int numberOfNumbers = 0, startIndex, finIndex;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>memset(pre, 0, 32768);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span></div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>ifstream from;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>ofstream output;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>output.open(&#8220;c29i.out&#8221;);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>from.open(&#8220;c29i.in&#8221;);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>from &gt;&gt; numberOfNumbers;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>cout &lt;&lt; &#8220;I read &#8221; &lt;&lt; numberOfNumbers &lt;&lt; &#8221; pairs of numbers &#8230;&#8221; &lt;&lt; endl;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>system(&#8220;pause&#8221;);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>cout &lt;&lt; &#8220;Starting program &#8221; &lt;&lt; endl;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>int gasite = 0;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>for(int k=0; k&lt;numberOfNumbers; k++)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>from &gt;&gt; startIndex;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>from &gt;&gt; finIndex;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>for(int i=startIndex ; i&lt;finIndex ; i++)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>num = i;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>if(pre[i] == 2)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>gasite++;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>else if(pre[i] == 0)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>memset(arr, 0, 30);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>while(num!= 0)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>arr[length++] = num%10;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>num/=10;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>if(!isLishel(arr, length, 0))</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>pre[i] = 2;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>gasite++;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>else</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>pre[i] = 1;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>length = 0;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>output &lt;&lt; k &lt;&lt; &#8220;: &#8221; &lt;&lt; &#8220;found between &#8221; &lt;&lt; startIndex &lt;&lt; &#8221; and &#8221; &lt;&lt; finIndex &lt;&lt; &#8221; : &#8221; &lt;&lt; gasite &lt;&lt;endl;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>gasite = 0;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>cout &lt;&lt; &#8220;Complete&#8230;&#8221; &lt;&lt; endl;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return 0;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">}</div>
<p><a title="Here" href="http://www.skullbox.info/concursuri-de-programare/(incepatori)(concurs-nr-29)numere-lychrel/" target="_blank"> </a>Here <a title="Here" href="http://www.skullbox.info/concursuri-de-programare/(incepatori)(concurs-nr-29)numere-lychrel/" target="_blank">(http://www.skullbox.info/concursuri-de-programare/(incepatori)(concurs-nr-29)numere-lychrel/)  </a>is a contest &#8230; the problem sounds like this:</p>
<p>- read N from <span style="font-family:verdana;line-height:16px;">&#8220;c29i.in&#8221; where 1&lt;= N &lt;= 10000;</span></p>
<p><span style="font-family:verdana;line-height:16px;">-read the N pairs of numbers from &#8221;c29i.in&#8221; wich are something like  &#8230; 0&lt;a&lt;b&lt;2^15</span></p>
<p><span style="font-family:verdana;line-height:16px;">-must output into &#8220;c29i.out&#8221; the number of Lychrel numbers between every pair of numbers [a, b] &#8230; the numbers are considered Lychrel if they do not turn into a polindrome after 100 aditions with himself reversed &#8230; (1239 + 9321)</span></p>
<p> </p>
<p><span style="font-family:verdana;line-height:16px;">mode about Lychrel numbers .. <a title="hhkh" href="http://en.wikipedia.org/wiki/Lychrel_number" target="_blank">http://en.wikipedia.org/wiki/Lychrel_number</a></span></p>
<p>#include &lt;iostream&gt;</p>
<p>#include &lt;fstream&gt;</p>
<p> </p>
<p>using namespace std;</p>
<p> </p>
<p>bool isPoli(int* arr, int length)</p>
<p>{</p>
<p><span style="white-space:pre;"> </span>for(int i=0; i&lt;length/2; i++)</p>
<p><span style="white-space:pre;"> </span>if(arr[i] != arr[length-i-1])</p>
<p><span style="white-space:pre;"> </span>return false;</p>
<p><span style="white-space:pre;"> </span>return true;</p>
<p>}</p>
<p> </p>
<p>bool isLishel(int* numArray, int length, int depth)</p>
<p>{</p>
<p><span style="white-space:pre;"> </span>/* IF I REACH DEPTH OF 100 JUST LEAVE IT &#8230; </p>
<p><span style="white-space:pre;"> </span> * &#8230; CAN CHANGE TO ANY DEPTH &#8230; JUST NEED </p>
<p><span style="white-space:pre;"> </span> * TO HAVE VERY FAST CPU</p>
<p><span style="white-space:pre;"> </span> */</p>
<p><span style="white-space:pre;"> </span>if(++depth == 100) return false;</p>
<p><span style="white-space:pre;"> </span>int rest = 0;</p>
<p><span style="white-space:pre;"> </span>int *fin = new int[length+1];</p>
<p> </p>
<p><span style="white-space:pre;"> </span>for(int i = 0 ; i &lt; length; i ++)</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>fin[i] = (numArray[i]+numArray[length-i-1]+rest)%10;</p>
<p><span style="white-space:pre;"> </span>rest = (numArray[i]+numArray[length-i-1]+rest)/10;</p>
<p><span style="white-space:pre;"> </span>}</p>
<p><span style="white-space:pre;"> </span>int l = length;</p>
<p><span style="white-space:pre;"> </span>if(rest != 0)</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>l++;</p>
<p><span style="white-space:pre;"> </span>fin[length] = rest;</p>
<p><span style="white-space:pre;"> </span>}</p>
<p><span style="white-space:pre;"> </span></p>
<p><span style="white-space:pre;"> </span>if(isPoli(fin, l))</p>
<p><span style="white-space:pre;"> </span>return true;</p>
<p> </p>
<p><span style="white-space:pre;"> </span>if(isLishel(fin, l, depth))</p>
<p><span style="white-space:pre;"> </span>return true;</p>
<p> </p>
<p><span style="white-space:pre;"> </span>return false;</p>
<p>}</p>
<p> </p>
<p>int main()</p>
<p>{</p>
<p><span style="white-space:pre;"> </span>int num, *arr;</p>
<p><span style="white-space:pre;"> </span>int num2 = 0;</p>
<p><span style="white-space:pre;"> </span>int length = 0;</p>
<p> </p>
<p><span style="white-space:pre;"> </span>arr = new int[30];</p>
<p><span style="white-space:pre;"> </span>int *pre = new int[32768];</p>
<p><span style="white-space:pre;"> </span>int idx = 0;</p>
<p><span style="white-space:pre;"> </span>int numberOfNumbers = 0, startIndex, finIndex;</p>
<p><span style="white-space:pre;"> </span>memset(pre, 0, 32768);</p>
<p><span style="white-space:pre;"> </span></p>
<p><span style="white-space:pre;"> </span>ifstream from;</p>
<p><span style="white-space:pre;"> </span>ofstream output;</p>
<p> </p>
<p><span style="white-space:pre;"> </span>output.open(&#8220;c29i.out&#8221;);</p>
<p><span style="white-space:pre;"> </span>from.open(&#8220;c29i.in&#8221;);</p>
<p> </p>
<p><span style="white-space:pre;"> </span>from &gt;&gt; numberOfNumbers;</p>
<p><span style="white-space:pre;"> </span>cout &lt;&lt; &#8220;I read &#8221; &lt;&lt; numberOfNumbers &lt;&lt; &#8221; pairs of numbers &#8230;&#8221; &lt;&lt; endl;</p>
<p><span style="white-space:pre;"> </span>system(&#8220;pause&#8221;);</p>
<p><span style="white-space:pre;"> </span>cout &lt;&lt; &#8220;Starting program &#8221; &lt;&lt; endl;</p>
<p><span style="white-space:pre;"> </span>int gasite = 0;</p>
<p><span style="white-space:pre;"> </span>for(int k=0; k&lt;numberOfNumbers; k++)</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>from &gt;&gt; startIndex;</p>
<p><span style="white-space:pre;"> </span>from &gt;&gt; finIndex;</p>
<p><span style="white-space:pre;"> </span>for(int i=startIndex ; i&lt;finIndex ; i++)</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>num = i;</p>
<p><span style="white-space:pre;"> </span>if(pre[i] == 2)</p>
<p><span style="white-space:pre;"> </span>gasite++;</p>
<p><span style="white-space:pre;"> </span>else if(pre[i] == 0)</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>memset(arr, 0, 30);</p>
<p><span style="white-space:pre;"> </span>while(num!= 0)</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>arr[length++] = num%10;</p>
<p><span style="white-space:pre;"> </span>num/=10;</p>
<p><span style="white-space:pre;"> </span>}</p>
<p> </p>
<p><span style="white-space:pre;"> </span>if(!isLishel(arr, length, 0))</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>pre[i] = 2;</p>
<p><span style="white-space:pre;"> </span>gasite++;</p>
<p><span style="white-space:pre;"> </span>}</p>
<p><span style="white-space:pre;"> </span>else</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>pre[i] = 1;</p>
<p><span style="white-space:pre;"> </span>}</p>
<p><span style="white-space:pre;"> </span>length = 0;</p>
<p><span style="white-space:pre;"> </span>}</p>
<p><span style="white-space:pre;"> </span>}</p>
<p><span style="white-space:pre;"> </span>output &lt;&lt; k &lt;&lt; &#8220;: &#8221; &lt;&lt; &#8220;found between &#8221; &lt;&lt; startIndex &lt;&lt; &#8221; and &#8221; &lt;&lt; finIndex &lt;&lt; &#8221; : &#8221; &lt;&lt; gasite &lt;&lt;endl;</p>
<p><span style="white-space:pre;"> </span>gasite = 0;</p>
<p><span style="white-space:pre;"> </span>}</p>
<p> </p>
<p><span style="white-space:pre;"> </span>cout &lt;&lt; &#8220;Complete&#8230;&#8221; &lt;&lt; endl;</p>
<p><span style="white-space:pre;"> </span>return 0;</p>
<p>}</p>
<p> </p>
<p>this code 2-3 days ago did not cracked &#8230; today it seems that it dies right after writing all the numbers to the &#8220;c29i.out&#8221; file <img src='http://s0.wp.com/wp-includes/images/smilies/icon_neutral.gif' alt=':|' class='wp-smiley' /> </p>
<p> </p>
<p>yes and another thing &#8230; here is a sample of  &#8221;c29i.in&#8221; file</p>
<p>(3 lines folowed by 3 pairs [a, b])</p>
<p>3 </p>
<p>10  10000</p>
<p>123  34512</p>
<p>5127 15000</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sinea.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sinea.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sinea.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sinea.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sinea.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sinea.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sinea.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sinea.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sinea.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sinea.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sinea.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sinea.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sinea.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sinea.wordpress.com/44/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sinea.wordpress.com&amp;blog=7696586&amp;post=44&amp;subd=sinea&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sinea.wordpress.com/2009/06/07/lychrel-numbers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e7dd8e0de54fd63f995aa3b9014d3fdd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sinea</media:title>
		</media:content>
	</item>
		<item>
		<title>my very own Array class -&gt;  like iterator pattern :)</title>
		<link>http://sinea.wordpress.com/2009/05/17/my-very-own-array-class-like-iterator-pattern/</link>
		<comments>http://sinea.wordpress.com/2009/05/17/my-very-own-array-class-like-iterator-pattern/#comments</comments>
		<pubDate>Sun, 17 May 2009 21:08:13 +0000</pubDate>
		<dc:creator>sinea</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[c++ Array]]></category>
		<category><![CDATA[clowns]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[iterator pattern]]></category>
		<category><![CDATA[pattern]]></category>

		<guid isPermaLink="false">http://sinea.wordpress.com/?p=39</guid>
		<description><![CDATA[Hello i have implemented a Array class with wich i(and you) can make an array of objects(any object), automaticaly search it for a certain object, send objects from inside an array to another. For now it&#8217;s very simple beacause i don&#8217;t have time to write one with much more useful things&#8230; hopefully will help someone. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sinea.wordpress.com&amp;blog=7696586&amp;post=39&amp;subd=sinea&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hello i have implemented a Array class with wich i(and you) can make an array of objects(any object), automaticaly search it for a certain object, send objects from inside an array to another. For now it&#8217;s very simple beacause i don&#8217;t have time to write one with much more useful things&#8230; hopefully will help someone. I made this at seing the list class &#8230; i don&#8217;t like it &#8230; just looks so stiff  :| . Hhere&#8217;s the code .. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">#include &lt;iostream&gt;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">using namespace std;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">/*<span style="white-space:pre;"> </span>Array class writen by &#8230; (just visit sinea.wordpress.com)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"> *<span style="white-space:pre;"> </span>this has to be something like list in c++</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"> *<span style="white-space:pre;"> </span>but much easier to use by overloading some</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"> *<span style="white-space:pre;"> </span>operators .. </div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"> *<span style="white-space:pre;"> </span>TODO :   &#8211; extend functionality</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"> *<span style="white-space:pre;"> </span>[- get a life <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ) ] </div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"> */</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">template &lt;class T&gt;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">class Array</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>T* objects;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>bool fixedLength;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>int numberOfObjects;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">public:</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>Array(int length = 0, bool fix = false)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>fixedLength = fix;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>if(length != 0)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>objects = new T[length];</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>else</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>objects = new T[];</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>numberOfObjects = 0;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>};</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>//ADD NEW  T ITEM AT THE END OF THE ARRAY AND RETURN IT</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>T&amp; push(T object)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>objects[numberOfObjects++] = object;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return objects[0];</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>//REMOVE THE LAST OBJECT OF THE ARRAY AND RETURN THE NEW LAST ONE</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>T&amp; pop()</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>objects[numberOfObjects] = NULL;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>numberOfObjects&#8211;;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return objects[numberOfObjects];</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>//SWITCH 2 OBJECTS IN THE ARRAY RETURN BOOL ACCORDINGLY(SUCCES OR NOT)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>bool switchObjects(int firstIndex, int secondIndex)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>if(firstIndex &gt;= numberOfObjects || secondIndex &gt;= numberOfObjects)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>throw &#8220;WTF IS WITH THAT INDEX :O &#8220;;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>try</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>T temp = objects[firstIndex];</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>objects[firstIndex] = objects[secondIndex];</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>objects[secondIndex] = temp;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>catch(&#8230;)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return false;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return true;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>//FIND OUT THE INDEX OF A OBJECT STARTING FROM THE GIVEN INDEX AND RETURN -1 IF THE OBJECT DOES NOT EXIST</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>int idexOf(T object, int starIndex = 0)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>for(int i = starIndex;  i &lt; numberOfObjects; i ++)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>if(objects[i] == object)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return i;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return -1;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>//RETURN THE CURENT LENGTH OF THE ARRAY</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>int Length() const</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return numberOfObjects;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>//CLEAN THE ARRAY AND RETURN BOOL(SUCCES OR FAILURE)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>bool Clean()</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>try</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>for(int i = 0;  i &lt; numberOfObjects; i ++)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>objects[i] = NULL;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>numberOfObjects = 0;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>catch(&#8230;)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return false;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return true;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>//EASY RETURN THE ITEM FROM A ARRAY BY USING THE [] OPERATOR(OVERLOADED)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>T&amp; operator[](int index)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>if(index &gt;= numberOfObjects)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>throw &#8220;WTF IS WITH THAT INDEX :O &#8220;;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return objects[index];</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>// USE THIS IF WE WANT TO CONCATENATE 2 ARRAYS</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>bool operator+=(Array&amp; from)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>for(int i = 0; i &lt; from.Length() ; i ++)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>push(from[i]);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return true;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>// USE IF WE WANT THIS ARRAY TO SEND THE OBJECTS AT THE INDEXS SPECIFIED IN THE elements[]</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>void SendElements(Array&amp; to, int elements[], int nElements)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>for(int i = 0; i &lt; nElements; i++)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>to.push(objects[elements[i]]);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">};</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">int main()</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>Array&lt;int&gt; arr;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>arr.push(10);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>arr.push(101);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>arr.push(12);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span></div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>Array&lt;int&gt; aray2;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>aray2.push(88);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>aray2.push(99);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span></div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>for(int i=0; i&lt;arr.Length(); i++)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>cout &lt;&lt; arr[i] &lt;&lt; &#8221; &#8220;;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>cout &lt;&lt; endl;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span></div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>arr.switchObjects(1, 2);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span></div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>for(int i=0; i&lt;arr.Length(); i++)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>cout &lt;&lt; arr[i] &lt;&lt; &#8221; &#8220;;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>cout &lt;&lt; endl;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>arr += aray2;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>int elem[] = {0, 1};</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>aray2.SendElements(arr, elem, 2);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>aray2 = arr;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>cout &lt;&lt; &#8220;aray2 &#8220;;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>for(int i=0; i&lt;aray2.Length(); i++)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>cout &lt;&lt; aray2[i] &lt;&lt; &#8221; &#8220;;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>cout &lt;&lt; endl;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>cout &lt;&lt; &#8220;arr &#8220;;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>for(int i=0; i&lt;arr.Length(); i++)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>cout &lt;&lt; arr[i] &lt;&lt; &#8221; &#8220;;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>cout &lt;&lt; endl;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return 0;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">}</div>
<p>#include &lt;iostream&gt;</p>
<p>using namespace std;</p>
<p> </p>
<p>/*<span style="white-space:pre;"> </span>Array class writen by &#8230; (just visit sinea.wordpress.com)</p>
<p> *<span style="white-space:pre;"> </span>this has to be something like list in c++</p>
<p> *<span style="white-space:pre;"> </span>but much easier to use by overloading some</p>
<p> *<span style="white-space:pre;"> </span>operators &#8230; and adding some fancy functionality</p>
<p> *<span style="white-space:pre;"> </span>TODO :   &#8211; extend functionality</p>
<p> *<span style="white-space:pre;"> </span>[- get a life <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ) ] </p>
<p> */</p>
<p>template &lt;class T&gt;</p>
<p>class Array</p>
<p>{</p>
<p><span style="white-space:pre;"> </span>T* objects;</p>
<p><span style="white-space:pre;"> </span>bool fixedLength; // ACTUALLY DOES NOT HELP WITH ANYTHING <img src='http://s2.wp.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<p><span style="white-space:pre;"> </span>int numberOfObjects;</p>
<p>public:</p>
<p><span style="white-space:pre;"> </span>Array(int length = 0, bool fix = false)</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>fixedLength = fix;</p>
<p><span style="white-space:pre;"> </span>if(length != 0)</p>
<p><span style="white-space:pre;"> </span>objects = new T[length];</p>
<p><span style="white-space:pre;"> </span>else</p>
<p><span style="white-space:pre;"> </span>objects = new T[];</p>
<p><span style="white-space:pre;"> </span>numberOfObjects = 0;</p>
<p><span style="white-space:pre;"> </span>};</p>
<p><span style="white-space:pre;"> </span>//ADD NEW  T ITEM AT THE END OF THE ARRAY AND RETURN IT</p>
<p><span style="white-space:pre;"> </span>T&amp; push(T object)</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>objects[numberOfObjects++] = object;</p>
<p><span style="white-space:pre;"> </span>return objects[0];</p>
<p><span style="white-space:pre;"> </span>}</p>
<p><span style="white-space:pre;"> </span>//REMOVE THE LAST OBJECT OF THE ARRAY AND RETURN THE NEW LAST ONE</p>
<p><span style="white-space:pre;"> </span>T&amp; pop()</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>objects[numberOfObjects] = NULL;</p>
<p><span style="white-space:pre;"> </span>numberOfObjects&#8211;;</p>
<p><span style="white-space:pre;"> </span>return objects[numberOfObjects];</p>
<p><span style="white-space:pre;"> </span>}</p>
<p><span style="white-space:pre;"> </span>//SWITCH 2 OBJECTS IN THE ARRAY RETURN BOOL ACCORDINGLY(SUCCES OR NOT)</p>
<p><span style="white-space:pre;"> </span>bool switchObjects(int firstIndex, int secondIndex)</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>if(firstIndex &gt;= numberOfObjects || secondIndex &gt;= numberOfObjects)</p>
<p><span style="white-space:pre;"> </span>throw &#8220;WTF IS WITH THAT INDEX :O &#8220;;</p>
<p><span style="white-space:pre;"> </span>try</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>T temp = objects[firstIndex];</p>
<p><span style="white-space:pre;"> </span>objects[firstIndex] = objects[secondIndex];</p>
<p><span style="white-space:pre;"> </span>objects[secondIndex] = temp;</p>
<p><span style="white-space:pre;"> </span>}</p>
<p><span style="white-space:pre;"> </span>catch(&#8230;)</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>return false;</p>
<p><span style="white-space:pre;"> </span>}</p>
<p><span style="white-space:pre;"> </span>return true;</p>
<p><span style="white-space:pre;"> </span>}</p>
<p><span style="white-space:pre;"> </span>//FIND OUT THE INDEX OF A OBJECT STARTING FROM THE GIVEN INDEX AND RETURN -1 IF THE OBJECT DOES NOT EXIST</p>
<p><span style="white-space:pre;"> </span>int idexOf(T object, int starIndex = 0)</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>for(int i = starIndex;  i &lt; numberOfObjects; i ++)</p>
<p><span style="white-space:pre;"> </span>if(objects[i] == object)</p>
<p><span style="white-space:pre;"> </span>return i;</p>
<p><span style="white-space:pre;"> </span>return -1;</p>
<p><span style="white-space:pre;"> </span>}</p>
<p><span style="white-space:pre;"> </span>//RETURN THE CURENT LENGTH OF THE ARRAY</p>
<p><span style="white-space:pre;"> </span>int Length() const</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>return numberOfObjects;</p>
<p><span style="white-space:pre;"> </span>}</p>
<p><span style="white-space:pre;"> </span>//CLEAN THE ARRAY AND RETURN BOOL(SUCCES OR FAILURE)</p>
<p><span style="white-space:pre;"> </span>bool Clean()</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>try</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>for(int i = 0;  i &lt; numberOfObjects; i ++)</p>
<p><span style="white-space:pre;"> </span>objects[i] = NULL;</p>
<p><span style="white-space:pre;"> </span>numberOfObjects = 0;</p>
<p><span style="white-space:pre;"> </span>}</p>
<p><span style="white-space:pre;"> </span>catch(&#8230;)</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>return false;</p>
<p><span style="white-space:pre;"> </span>}</p>
<p><span style="white-space:pre;"> </span>return true;</p>
<p><span style="white-space:pre;"> </span>}</p>
<p><span style="white-space:pre;"> </span>//EASY RETURN THE ITEM FROM A ARRAY BY USING THE [] OPERATOR(OVERLOADED)</p>
<p><span style="white-space:pre;"> </span>T&amp; operator[](int index)</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>if(index &gt;= numberOfObjects)</p>
<p><span style="white-space:pre;"> </span>throw &#8220;WTF IS WITH THAT INDEX :O &#8220;;</p>
<p><span style="white-space:pre;"> </span>return objects[index];</p>
<p><span style="white-space:pre;"> </span>}</p>
<p><span style="white-space:pre;"> </span>// USE THIS IF WE WANT TO CONCATENATE 2 ARRAYS</p>
<p><span style="white-space:pre;"> </span>bool operator+=(Array&amp; from)</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>for(int i = 0; i &lt; from.Length() ; i ++)</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>push(from[i]);</p>
<p><span style="white-space:pre;"> </span>}</p>
<p><span style="white-space:pre;"> </span>return true;</p>
<p><span style="white-space:pre;"> </span>}</p>
<p><span style="white-space:pre;"> </span>// USE IF WE WANT THIS ARRAY TO SEND THE OBJECTS AT THE INDEXS SPECIFIED IN THE elements[]</p>
<p><span style="white-space:pre;"> </span>void SendElements(Array&amp; to, int elements[], int nElements)</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>for(int i = 0; i &lt; nElements; i++)</p>
<p><span style="white-space:pre;"> </span>to.push(objects[elements[i]]);</p>
<p><span style="white-space:pre;"> </span>}</p>
<p>};</p>
<p> </p>
<p>int main()</p>
<p>{</p>
<p><span style="white-space:pre;"> </span>Array&lt;int&gt; arr;</p>
<p><span style="white-space:pre;"> </span>arr.push(10);</p>
<p><span style="white-space:pre;"> </span>arr.push(101);</p>
<p><span style="white-space:pre;"> </span>arr.push(12);</p>
<p><span style="white-space:pre;"> </span></p>
<p><span style="white-space:pre;"> </span>Array&lt;int&gt; aray2;</p>
<p><span style="white-space:pre;"> </span>aray2.push(88);</p>
<p><span style="white-space:pre;"> </span>aray2.push(99);</p>
<p><span style="white-space:pre;"> </span></p>
<p><span style="white-space:pre;"> </span>for(int i=0; i&lt;arr.Length(); i++)</p>
<p><span style="white-space:pre;"> </span>cout &lt;&lt; arr[i] &lt;&lt; &#8221; &#8220;;</p>
<p><span style="white-space:pre;"> </span>cout &lt;&lt; endl;</p>
<p><span style="white-space:pre;"> </span></p>
<p><span style="white-space:pre;"> </span>arr.switchObjects(1, 2);</p>
<p><span style="white-space:pre;"> </span></p>
<p><span style="white-space:pre;"> </span>for(int i=0; i&lt;arr.Length(); i++)</p>
<p><span style="white-space:pre;"> </span>cout &lt;&lt; arr[i] &lt;&lt; &#8221; &#8220;;</p>
<p><span style="white-space:pre;"> </span>cout &lt;&lt; endl;</p>
<p> </p>
<p><span style="white-space:pre;"> </span>arr += aray2;</p>
<p><span style="white-space:pre;"> </span>int elem[] = {0, 1};</p>
<p> </p>
<p><span style="white-space:pre;"> </span>aray2.SendElements(arr, elem, 2);</p>
<p> </p>
<p><span style="white-space:pre;"> </span>aray2 = arr;</p>
<p><span style="white-space:pre;"> </span>cout &lt;&lt; &#8220;aray2 &#8220;;</p>
<p><span style="white-space:pre;"> </span>for(int i=0; i&lt;aray2.Length(); i++)</p>
<p><span style="white-space:pre;"> </span>cout &lt;&lt; aray2[i] &lt;&lt; &#8221; &#8220;;</p>
<p><span style="white-space:pre;"> </span>cout &lt;&lt; endl;</p>
<p> </p>
<p><span style="white-space:pre;"> </span>cout &lt;&lt; &#8220;arr &#8220;;</p>
<p><span style="white-space:pre;"> </span>for(int i=0; i&lt;arr.Length(); i++)</p>
<p><span style="white-space:pre;"> </span>cout &lt;&lt; arr[i] &lt;&lt; &#8221; &#8220;;</p>
<p><span style="white-space:pre;"> </span>cout &lt;&lt; endl;</p>
<p> </p>
<p><span style="white-space:pre;"> </span>return 0;</p>
<p>}</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sinea.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sinea.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sinea.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sinea.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sinea.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sinea.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sinea.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sinea.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sinea.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sinea.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sinea.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sinea.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sinea.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sinea.wordpress.com/39/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sinea.wordpress.com&amp;blog=7696586&amp;post=39&amp;subd=sinea&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sinea.wordpress.com/2009/05/17/my-very-own-array-class-like-iterator-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e7dd8e0de54fd63f995aa3b9014d3fdd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sinea</media:title>
		</media:content>
	</item>
		<item>
		<title>The Singleton design pattern</title>
		<link>http://sinea.wordpress.com/2009/05/16/the-singleton-design-pattern/</link>
		<comments>http://sinea.wordpress.com/2009/05/16/the-singleton-design-pattern/#comments</comments>
		<pubDate>Sat, 16 May 2009 18:58:49 +0000</pubDate>
		<dc:creator>sinea</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[pattern]]></category>
		<category><![CDATA[singleton]]></category>
		<category><![CDATA[sound manager class]]></category>

		<guid isPermaLink="false">http://sinea.wordpress.com/?p=34</guid>
		<description><![CDATA[Hy there, here&#8217;s a singleton class(SoundManager). Using a singleton design pattern is very useful, at least that&#8217;s what i use in game developement.  This design pattern make your life easy beacause it has only one instance.. again .. ONLY ONE  :)  threfore you can call the static member function getInstance() to obtain the single instance [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sinea.wordpress.com&amp;blog=7696586&amp;post=34&amp;subd=sinea&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hy there, here&#8217;s a singleton class(SoundManager). Using a singleton design pattern is very useful, at least that&#8217;s what i use in game developement.  This design pattern make your life easy beacause it has only one instance.. again .. ONLY ONE  :)  threfore you can call the static member function getInstance() to obtain the single instance of the class from anywhere in the code &#8230; enaugh said .. the rest is code <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>made just to prove the singleton pattern</p>
<p> </p>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">#include &lt;iostream&gt;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">using namespace std;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">class Sound{};</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">class SoundManager</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>static SoundManager * instance;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>static int numberOfInstances;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>Sound * sounds;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>int numberOfSounds;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>SoundManager()</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{ </div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>sounds = new Sound[]; // DYNAMIC ARRAY OF SOUNDS</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>numberOfSounds = 0;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>};</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">public:</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>~SoundManager(){ numberOfInstances &#8212; ; /*IF WE DESTROY A INSTANCE OF THE SINGLETON WITH delete() WE MUST DECREMENT THE NUMBER OF INSTANCES*/};</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>static SoundManager * getInstance();</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>void addSound(Sound sound);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>int howManySounds();</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>int howManyInstances();</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">};</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">int SoundManager::numberOfInstances = 0; // INITIALIZE THE NUMBER OF INSTANCES WITH 0</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">SoundManager* SoundManager::instance = NULL; // MAKE THE INITIAL INSTANCE NULL</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">SoundManager * SoundManager::getInstance()</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>if(numberOfInstances == 0) // IF THE NUMBER OF INSTANCES IS 0 (NONE HAS BEEN MADE YET)  &#8230; </div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>instance = new SoundManager(); // WE SHOULD MAKE A NEW ONE &#8230; RIGHT ? <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span></div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>numberOfInstances ++ ; // INCREMENT THE INSTANCE COUNTER</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return instance;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">// .. THE REST IS HISTORY</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">void SoundManager::addSound(Sound sound)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>cout &lt;&lt; &#8221; &#8211; added sound &#8211; &#8221; &lt;&lt; endl;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>sounds[numberOfSounds++] = sound;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">int SoundManager::howManySounds()</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return numberOfSounds;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">int SoundManager::howManyInstances()</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return numberOfInstances;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">int main()</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>SoundManager *s1, *s2;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>Sound s,a,b,c;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>s1 = SoundManager::getInstance();</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>s2 = SoundManager::getInstance();</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span></div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>s1-&gt;addSound(s);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>s1-&gt;addSound(a);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>s1-&gt;addSound(b);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>s1-&gt;addSound(c);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>cout &lt;&lt; &#8221; No instances : &#8221; &lt;&lt; s1-&gt;howManyInstances() &lt;&lt; endl; // WE NOW HAVE JUST 2 INSTANCES OF TRHE OBJECT BUT ONLY ONE OBJECT</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>cout &lt;&lt; &#8221; No sounds : &#8221; &lt;&lt; s2-&gt;howManySounds() &lt;&lt; endl; // WE HAVE 4 SOUNDS</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>cout &lt;&lt; &#8221; No sounds : &#8221; &lt;&lt; s1-&gt;howManySounds() &lt;&lt; endl; // STIL 4 SOUNDS BEACAUSE THE S1 POINTS AT THE SAME INSTANCE AS S2</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>// LET&#8217;S MAKE ANOTHER INSTANCE &#8230; BUT NOT A NEW OBJECT &#8230;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>SoundManager *lastInstance = SoundManager::getInstance();</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>cout &lt;&lt; &#8221; No sounds : &#8221; &lt;&lt; lastInstance-&gt;howManySounds() &lt;&lt; endl; // YEP STIL 4 SOUNDS <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>cout &lt;&lt; &#8221; No instances : &#8221; &lt;&lt; lastInstance-&gt;howManyInstances() &lt;&lt; endl;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return 0;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">}</div>
<p>#include &lt;iostream&gt;</p>
<p>using namespace std;</p>
<p>class Sound{};</p>
<p> </p>
<p>class SoundManager</p>
<p>{</p>
<p><span style="white-space:pre;"> </span>static SoundManager * instance;</p>
<p><span style="white-space:pre;"> </span>static int numberOfInstances;</p>
<p><span style="white-space:pre;"> </span>Sound * sounds;</p>
<p><span style="white-space:pre;"> </span>int numberOfSounds;</p>
<p><span style="white-space:pre;"> </span>SoundManager()</p>
<p><span style="white-space:pre;"> </span>{ </p>
<p><span style="white-space:pre;"> </span>sounds = new Sound[]; // DYNAMIC ARRAY OF SOUNDS</p>
<p><span style="white-space:pre;"> </span>numberOfSounds = 0;</p>
<p><span style="white-space:pre;"> </span>};</p>
<p>public:</p>
<p><span style="white-space:pre;"> </span>~SoundManager(){ numberOfInstances &#8212; ; /*IF WE DESTROY A REFERENCE TO THE SINGLETON WITH delete() WE MUST DECREMENT THE NUMBER OF REFERENCE */};</p>
<p><span style="white-space:pre;"> </span>static SoundManager * getInstance();</p>
<p><span style="white-space:pre;"> </span>void addSound(Sound sound);</p>
<p><span style="white-space:pre;"> </span>int howManySounds();</p>
<p><span style="white-space:pre;"> </span>int howManyInstances();</p>
<p>};</p>
<p> </p>
<p>int SoundManager::numberOfInstances = 0; // INITIALIZE THE NUMBER OF INSTANCES WITH 0</p>
<p>SoundManager* SoundManager::instance = NULL; // MAKE THE INITIAL INSTANCE NULL</p>
<p> </p>
<p>SoundManager * SoundManager::getInstance()</p>
<p>{</p>
<p><span style="white-space:pre;"> </span>if(numberOfInstances == 0) // IF THE NUMBER OF REFS IS 0 (NONE HAS BEEN MADE YET)  &#8230; </p>
<p><span style="white-space:pre;"> </span>instance = new SoundManager(); // WE SHOULD MAKE A NEW ONE &#8230; RIGHT ? <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><span style="white-space:pre;"> </span></p>
<p><span style="white-space:pre;"> </span>numberOfInstances ++ ; // INCREMENT THE REFS COUNTER</p>
<p><span style="white-space:pre;"> </span>return instance;</p>
<p>}</p>
<p>// .. THE REST IS HISTORY</p>
<p>void SoundManager::addSound(Sound sound)</p>
<p>{</p>
<p><span style="white-space:pre;"> </span>cout &lt;&lt; &#8221; &#8211; added sound &#8211; &#8221; &lt;&lt; endl;</p>
<p><span style="white-space:pre;"> </span>sounds[numberOfSounds++] = sound;</p>
<p>}</p>
<p> </p>
<p>int SoundManager::howManySounds()</p>
<p>{</p>
<p><span style="white-space:pre;"> </span>return numberOfSounds;</p>
<p>}</p>
<p> </p>
<p>int SoundManager::howManyInstances()</p>
<p>{</p>
<p><span style="white-space:pre;"> </span>return numberOfInstances;</p>
<p>}</p>
<p>int main()</p>
<p>{</p>
<p><span style="white-space:pre;"> </span>SoundManager *s1, *s2;</p>
<p><span style="white-space:pre;"> </span>Sound s,a,b,c;</p>
<p><span style="white-space:pre;"> </span>s1 = SoundManager::getInstance();</p>
<p><span style="white-space:pre;"> </span>s2 = SoundManager::getInstance();</p>
<p><span style="white-space:pre;"> </span></p>
<p><span style="white-space:pre;"> </span>s1-&gt;addSound(s);</p>
<p><span style="white-space:pre;"> </span>s1-&gt;addSound(a);</p>
<p><span style="white-space:pre;"> </span>s1-&gt;addSound(b);</p>
<p><span style="white-space:pre;"> </span>s1-&gt;addSound(c);</p>
<p> </p>
<p><span style="white-space:pre;"> </span>cout &lt;&lt; &#8221; No instances : &#8221; &lt;&lt; s1-&gt;howManyInstances() &lt;&lt; endl; // WE NOW HAVE JUST 2 POINTERS TO THE OBJECT BUT ONLY ONE OBJECT</p>
<p> </p>
<p><span style="white-space:pre;"> </span>cout &lt;&lt; &#8221; No sounds : &#8221; &lt;&lt; s2-&gt;howManySounds() &lt;&lt; endl; // WE HAVE 4 SOUNDS</p>
<p><span style="white-space:pre;"> </span>cout &lt;&lt; &#8221; No sounds : &#8221; &lt;&lt; s1-&gt;howManySounds() &lt;&lt; endl; // STIL 4 SOUNDS BEACAUSE THE S1 POINTS AT THE SAME INSTANCE AS S2</p>
<p> </p>
<p><span style="white-space:pre;"> </span>// LET&#8217;S MAKE ANOTHER POINTER AT THE SINGLETON CLASS&#8230; BUT NOT A NEW OBJECT &#8230;</p>
<p><span style="white-space:pre;"> </span>SoundManager *lastInstance = SoundManager::getInstance();</p>
<p><span style="white-space:pre;"> </span>cout &lt;&lt; &#8221; No sounds : &#8221; &lt;&lt; lastInstance-&gt;howManySounds() &lt;&lt; endl; // YEP STIL 4 SOUNDS <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p> </p>
<p><span style="white-space:pre;"> </span>cout &lt;&lt; &#8221; No instances : &#8221; &lt;&lt; lastInstance-&gt;howManyInstances() &lt;&lt; endl;</p>
<p> </p>
<p><span style="white-space:pre;"> </span>return 0;</p>
<p>}</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sinea.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sinea.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sinea.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sinea.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sinea.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sinea.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sinea.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sinea.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sinea.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sinea.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sinea.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sinea.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sinea.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sinea.wordpress.com/34/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sinea.wordpress.com&amp;blog=7696586&amp;post=34&amp;subd=sinea&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sinea.wordpress.com/2009/05/16/the-singleton-design-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e7dd8e0de54fd63f995aa3b9014d3fdd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sinea</media:title>
		</media:content>
	</item>
		<item>
		<title>Node class &#8230; can make a tree of strings and search the whole tree for a certain term</title>
		<link>http://sinea.wordpress.com/2009/05/14/node-class-can-make-a-tree-of-strings-and-search-the-whole-tree-for-a-certain-term/</link>
		<comments>http://sinea.wordpress.com/2009/05/14/node-class-can-make-a-tree-of-strings-and-search-the-whole-tree-for-a-certain-term/#comments</comments>
		<pubDate>Thu, 14 May 2009 20:19:26 +0000</pubDate>
		<dc:creator>sinea</dc:creator>
				<category><![CDATA[C/C++]]></category>

		<guid isPermaLink="false">http://sinea.wordpress.com/?p=28</guid>
		<description><![CDATA[  #include &#60;iostream&#62; using namespace std; class Node { char * m_value; int m_children; Node* children; public: Node(); void Text(char* text); char* Text() const; void AddChild(Node&#38; nod); bool GetNode(Node&#38; to, char* like); }; Node::Node() { m_children = 0; children = new Node[]; cout &#60;&#60; &#8220;BUILD&#8221; &#60;&#60; endl; } void Node::Text(char *text) { m_value = text; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sinea.wordpress.com&amp;blog=7696586&amp;post=28&amp;subd=sinea&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p> </p>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">#include &lt;iostream&gt;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">using namespace std;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">class Node</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>char * m_value;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>int m_children;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>Node* children;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">public:</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>Node();</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>void Text(char* text);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>char* Text() const;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>void AddChild(Node&amp; nod);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>bool GetNode(Node&amp; to, char* like);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">};</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">Node::Node()</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>m_children = 0;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>children = new Node[];</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>cout &lt;&lt; &#8220;BUILD&#8221; &lt;&lt; endl;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">void Node::Text(char *text)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>m_value = text;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>cout &lt;&lt; &#8220;SET VALUE : &#8221; &lt;&lt; m_value &lt;&lt; endl;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">char* Node::Text() const</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return m_value;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">void Node::AddChild(Node&amp; nod)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>children[m_children] = nod;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>m_children++;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">bool Node::GetNode(Node &amp;to, char *like)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>if(m_value == like)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>to = *this;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return true;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>for(int i=0; i&lt;m_children; i++)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>if(children[i].GetNode(to, like))</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return true;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return false;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">int main()</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>Node n;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>n.Text(&#8220;www&#8221;);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span></div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>Node a;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>a.Text(&#8220;bubu&#8221;);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>Node b;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>b.Text(&#8220;qwertyKeyboard&#8221;);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>Node c;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>c.Text(&#8220;apple&#8221;);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span></div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>Node aa;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>aa.Text(&#8220;sunny&#8221;);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>Node bb;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>bb.Text(&#8220;NAN&#8221;);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>Node cc;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>cc.Text(&#8220;Smiley&#8221;);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>a.AddChild(aa);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>a.AddChild(bb);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>a.AddChild(cc);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>n.AddChild(a);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>n.AddChild(b);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>n.AddChild(c);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>Node final;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>if(a.GetNode(final, &#8220;alina&#8221;))</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>cout &lt;&lt; final.Text() &lt;&lt; endl;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return 0;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">}</div>
<p>who knows .. maybe usefull sometime <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>#include &lt;iostream&gt;</p>
<p>using namespace std;</p>
<p>class Node</p>
<p>{</p>
<p><span style="white-space:pre;"> </span>char * m_value;</p>
<p><span style="white-space:pre;"> </span>int m_children;</p>
<p><span style="white-space:pre;"> </span>Node* children;</p>
<p>public:</p>
<p><span style="white-space:pre;"> </span>Node();</p>
<p><span style="white-space:pre;"> </span>void Text(char* text);</p>
<p><span style="white-space:pre;"> </span>char* Text() const;</p>
<p><span style="white-space:pre;"> </span>void AddChild(Node&amp; nod);</p>
<p><span style="white-space:pre;"> </span>bool GetNode(Node&amp; to, char* like);</p>
<p>};</p>
<p>Node::Node()</p>
<p>{</p>
<p><span style="white-space:pre;"> </span>m_children = 0;</p>
<p><span style="white-space:pre;"> </span>children = new Node[];</p>
<p><span style="white-space:pre;"> </span>cout &lt;&lt; &#8220;BUILD&#8221; &lt;&lt; endl;</p>
<p>}</p>
<p>void Node::Text(char *text)</p>
<p>{</p>
<p><span style="white-space:pre;"> </span>m_value = text;</p>
<p><span style="white-space:pre;"> </span>cout &lt;&lt; &#8220;SET VALUE : &#8221; &lt;&lt; m_value &lt;&lt; endl;</p>
<p>}</p>
<p>char* Node::Text() const</p>
<p>{</p>
<p><span style="white-space:pre;"> </span>return m_value;</p>
<p>}</p>
<p>void Node::AddChild(Node&amp; nod)</p>
<p>{</p>
<p><span style="white-space:pre;"> </span>children[m_children] = nod;</p>
<p><span style="white-space:pre;"> </span>m_children++;</p>
<p>}</p>
<p>bool Node::GetNode(Node &amp;to, char *like)</p>
<p>{</p>
<p><span style="white-space:pre;"> </span>if(m_value == like)</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>to = *this;</p>
<p><span style="white-space:pre;"> </span>return true;</p>
<p><span style="white-space:pre;"> </span>}</p>
<p> </p>
<p><span style="white-space:pre;"> </span>for(int i=0; i&lt;m_children; i++)</p>
<p><span style="white-space:pre;"> </span>if(children[i].GetNode(to, like))</p>
<p><span style="white-space:pre;"> </span>return true;</p>
<p> </p>
<p><span style="white-space:pre;"> </span>return false;</p>
<p>}</p>
<p> </p>
<p>int main()</p>
<p>{</p>
<p><span style="white-space:pre;"> </span>Node n;</p>
<p><span style="white-space:pre;"> </span>n.Text(&#8220;www&#8221;);</p>
<p><span style="white-space:pre;"> </span></p>
<p><span style="white-space:pre;"> </span>Node a;</p>
<p><span style="white-space:pre;"> </span>a.Text(&#8220;bubu&#8221;);</p>
<p><span style="white-space:pre;"> </span>Node b;</p>
<p><span style="white-space:pre;"> </span>b.Text(&#8220;qwertyKeyboard&#8221;);</p>
<p><span style="white-space:pre;"> </span>Node c;</p>
<p><span style="white-space:pre;"> </span>c.Text(&#8220;apple&#8221;);</p>
<p><span style="white-space:pre;"> </span></p>
<p> </p>
<p><span style="white-space:pre;"> </span>Node aa;</p>
<p><span style="white-space:pre;"> </span>aa.Text(&#8220;sunny&#8221;);</p>
<p><span style="white-space:pre;"> </span>Node bb;</p>
<p><span style="white-space:pre;"> </span>bb.Text(&#8220;NAN&#8221;);</p>
<p><span style="white-space:pre;"> </span>Node cc;</p>
<p><span style="white-space:pre;"> </span>cc.Text(&#8220;Smiley&#8221;);</p>
<p> </p>
<p><span style="white-space:pre;"> </span>a.AddChild(aa);</p>
<p><span style="white-space:pre;"> </span>a.AddChild(bb);</p>
<p><span style="white-space:pre;"> </span>a.AddChild(cc);</p>
<p> </p>
<p><span style="white-space:pre;"> </span>n.AddChild(a);</p>
<p><span style="white-space:pre;"> </span>n.AddChild(b);</p>
<p><span style="white-space:pre;"> </span>n.AddChild(c);</p>
<p> </p>
<p><span style="white-space:pre;"> </span>Node final;</p>
<p><span style="white-space:pre;"> </span>if(a.GetNode(final, &#8220;someTerm&#8221;))</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>cout &lt;&lt; final.Text() &lt;&lt; endl;</p>
<p><span style="white-space:pre;"> </span>}</p>
<p><span style="white-space:pre;"> </span>return 0;</p>
<p>}</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sinea.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sinea.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sinea.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sinea.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sinea.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sinea.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sinea.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sinea.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sinea.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sinea.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sinea.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sinea.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sinea.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sinea.wordpress.com/28/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sinea.wordpress.com&amp;blog=7696586&amp;post=28&amp;subd=sinea&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sinea.wordpress.com/2009/05/14/node-class-can-make-a-tree-of-strings-and-search-the-whole-tree-for-a-certain-term/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e7dd8e0de54fd63f995aa3b9014d3fdd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sinea</media:title>
		</media:content>
	</item>
		<item>
		<title>MyInt class &#8211; small to demonstrate operator overloading</title>
		<link>http://sinea.wordpress.com/2009/05/12/myint-class-small-to-demonstrate-operator-overloading/</link>
		<comments>http://sinea.wordpress.com/2009/05/12/myint-class-small-to-demonstrate-operator-overloading/#comments</comments>
		<pubDate>Tue, 12 May 2009 12:00:46 +0000</pubDate>
		<dc:creator>sinea</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[clowns]]></category>
		<category><![CDATA[operator overloading]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://sinea.wordpress.com/?p=23</guid>
		<description><![CDATA[  class MyInt { int m_number; public: MyInt(int number) { m_number = number; cout &#60;&#60; &#8220;NEW MYINT MADE. VALUE : &#8221; &#60;&#60; m_number &#60;&#60; endl; }; /* GETER FOR M_NUMBER */ int value() const { return m_number; } /* SHOW THE VALUE OF THE CONTAINED INTEGER */ void showValue() const { cout &#60;&#60; m_number &#60;&#60; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sinea.wordpress.com&amp;blog=7696586&amp;post=23&amp;subd=sinea&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p> </p>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">class MyInt</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>int m_number;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">public:</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>MyInt(int number)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>m_number = number;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>cout &lt;&lt; &#8220;NEW MYINT MADE. VALUE : &#8221; &lt;&lt; m_number &lt;&lt; endl;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>};</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>/* GETER FOR M_NUMBER */</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>int value() const</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return m_number;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>/* SHOW THE VALUE OF THE CONTAINED INTEGER */</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>void showValue() const</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>cout &lt;&lt; m_number &lt;&lt; endl;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>/* OVERLOAD THE + OPERATOR FOR THIS CLASS </div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span> * MAKE THE SUM OF THE TWO MEMBER VARS</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span> * AND RETURN A NEW OBJECT             */</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>MyInt operator+(MyInt&amp; rightValue)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>/* MAKE NEW MyInt OBJECT INITIALIZED </div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span> * WITH THE SUM OF THE 2 MEMBER INT&#8217;s </div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span> * rightValue IS THE ONE ON THE RIGHT </div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span> * OF THE + OPERATOR :p*/</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>MyInt rV(m_number + rightValue.value());</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>/* RETURN THE NEW OBJECT */</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return rV;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>MyInt operator*(MyInt&amp; rightValue)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>/* EXACTLY THE SAME AS THE + OPERATOR */</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>MyInt rV(m_number * rightValue.value());</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>/* RETURN THE NEW OBJECT */</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return rV;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>/* MAKING THE &lt; OPERATOR FOR OUR CLASS */</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>bool operator&lt;(MyInt&amp; rightValue)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>/* SAME AS + AND * THE rightValue IS THE </div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span> * OBJECT FROM THE RIGHT OF THE OPERATOR</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span> * AND THE ONE FROM THE LEFT IS THE </div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span> * CURENT(this) ONE*/</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>cout &lt;&lt; m_number &lt;&lt; &#8221; &lt; &#8221; &lt;&lt; rightValue.value() &lt;&lt; endl;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return m_number &lt; rightValue.value();</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>/* MAKING THE &gt; OPERATOR FOR OUR CLASS */</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>bool operator&gt;(MyInt&amp; rightValue)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>/* SAME AS + AND * THE rightValue IS THE </div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span> * OBJECT FROM THE RIGHT OF THE OPERATOR</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span> * AND THE ONE FROM THE LEFT IS THE </div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span> * CURENT(this) ONE*/</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>cout &lt;&lt; m_number &lt;&lt; &#8221; &gt; &#8221; &lt;&lt; rightValue.value() &lt;&lt; endl;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return m_number &gt; rightValue.value();</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>~MyInt(){};</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">};</div>
<p>Basic operator overloading in c++ for a class (MyInt in this case :p)</p>
<p>class MyInt</p>
<p>{</p>
<p>private:</p>
<p><span style="white-space:pre;"> </span>int m_number;</p>
<p>public:</p>
<p><span style="white-space:pre;"> </span>MyInt(int number)</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>m_number = number;</p>
<p><span style="white-space:pre;"> </span>cout &lt;&lt; &#8220;NEW MYINT MADE. VALUE : &#8221; &lt;&lt; m_number &lt;&lt; endl;</p>
<p><span style="white-space:pre;"> </span>};</p>
<p><span style="white-space:pre;"> </span>/* GETER FOR M_NUMBER */</p>
<p><span style="white-space:pre;"> </span>int value() const</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>return m_number;</p>
<p><span style="white-space:pre;"> </span>}</p>
<p><span style="white-space:pre;"> </span>/* SHOW THE VALUE OF THE CONTAINED INTEGER */</p>
<p><span style="white-space:pre;"> </span>void showValue() const</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>cout &lt;&lt; m_number &lt;&lt; endl;</p>
<p><span style="white-space:pre;"> </span>}</p>
<p><span style="white-space:pre;"> </span>/* OVERLOAD THE + OPERATOR FOR THIS CLASS </p>
<p><span style="white-space:pre;"> </span> * MAKE THE SUM OF THE TWO MEMBER VARS</p>
<p><span style="white-space:pre;"> </span> * AND RETURN A NEW OBJECT             */</p>
<p><span style="white-space:pre;"> </span>MyInt operator+(MyInt&amp; rightValue)</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>/* MAKE NEW MyInt OBJECT INITIALIZED </p>
<p><span style="white-space:pre;"> </span> * WITH THE SUM OF THE 2 MEMBER INT&#8217;s </p>
<p><span style="white-space:pre;"> </span> * rightValue IS THE ONE ON THE RIGHT </p>
<p><span style="white-space:pre;"> </span> * OF THE + OPERATOR :p*/</p>
<p><span style="white-space:pre;"> </span>MyInt rV(m_number + rightValue.value());</p>
<p><span style="white-space:pre;"> </span>/* RETURN THE NEW OBJECT */</p>
<p><span style="white-space:pre;"> </span>return rV;</p>
<p><span style="white-space:pre;"> </span>}</p>
<p> </p>
<p><span style="white-space:pre;"> </span>MyInt operator*(MyInt&amp; rightValue)</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>/* EXACTLY THE SAME AS THE + OPERATOR */</p>
<p><span style="white-space:pre;"> </span>MyInt rV(m_number * rightValue.value());</p>
<p><span style="white-space:pre;"> </span>/* RETURN THE NEW OBJECT */</p>
<p><span style="white-space:pre;"> </span>return rV;</p>
<p><span style="white-space:pre;"> </span>}</p>
<p><span style="white-space:pre;"> </span>/* MAKING THE &lt; OPERATOR FOR OUR CLASS */</p>
<p><span style="white-space:pre;"> </span>bool operator&lt;(MyInt&amp; rightValue)</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>/* SAME AS + AND * THE rightValue IS THE </p>
<p><span style="white-space:pre;"> </span> * OBJECT FROM THE RIGHT OF THE OPERATOR</p>
<p><span style="white-space:pre;"> </span> * AND THE ONE FROM THE LEFT IS THE </p>
<p><span style="white-space:pre;"> </span> * CURENT(this) ONE*/</p>
<p><span style="white-space:pre;"> </span>cout &lt;&lt; m_number &lt;&lt; &#8221; &lt; &#8221; &lt;&lt; rightValue.value() &lt;&lt; endl;</p>
<p><span style="white-space:pre;"> </span>return m_number &lt; rightValue.value();</p>
<p><span style="white-space:pre;"> </span>}</p>
<p><span style="white-space:pre;"> </span>/* MAKING THE &gt; OPERATOR FOR OUR CLASS */</p>
<p><span style="white-space:pre;"> </span>bool operator&gt;(MyInt&amp; rightValue)</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>/* SAME AS + AND * THE rightValue IS THE </p>
<p><span style="white-space:pre;"> </span> * OBJECT FROM THE RIGHT OF THE OPERATOR</p>
<p><span style="white-space:pre;"> </span> * AND THE ONE FROM THE LEFT IS THE </p>
<p><span style="white-space:pre;"> </span> * CURENT(this) ONE*/</p>
<p><span style="white-space:pre;"> </span>cout &lt;&lt; m_number &lt;&lt; &#8221; &gt; &#8221; &lt;&lt; rightValue.value() &lt;&lt; endl;</p>
<p><span style="white-space:pre;"> </span>return m_number &gt; rightValue.value();</p>
<p><span style="white-space:pre;"> </span>}</p>
<p><span style="white-space:pre;"> </span>~MyInt(){};</p>
<p>};</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sinea.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sinea.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sinea.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sinea.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sinea.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sinea.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sinea.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sinea.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sinea.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sinea.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sinea.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sinea.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sinea.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sinea.wordpress.com/23/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sinea.wordpress.com&amp;blog=7696586&amp;post=23&amp;subd=sinea&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sinea.wordpress.com/2009/05/12/myint-class-small-to-demonstrate-operator-overloading/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e7dd8e0de54fd63f995aa3b9014d3fdd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sinea</media:title>
		</media:content>
	</item>
		<item>
		<title>Goldbach&#8217;s conjecture made simple in c++</title>
		<link>http://sinea.wordpress.com/2009/05/11/goldbachs-conjecture-made-simple-in-c/</link>
		<comments>http://sinea.wordpress.com/2009/05/11/goldbachs-conjecture-made-simple-in-c/#comments</comments>
		<pubDate>Mon, 11 May 2009 15:36:00 +0000</pubDate>
		<dc:creator>sinea</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[conjecture]]></category>
		<category><![CDATA[Goldbach]]></category>
		<category><![CDATA[Goldbach's conjecture]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://sinea.wordpress.com/?p=15</guid>
		<description><![CDATA[  #include &#60;iostream.h&#62; #include &#60;math.h&#62; #include &#60;time.h&#62; bool isPrime(int&#38; x) {         if (x == 1 &#124;&#124; (x % 2 == 0 &#38;&#38; x != 2)) return false; if(x % 3 == 0) return false;         for (int i = 3; i &#60;= sqrt(x); i += 2)          [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sinea.wordpress.com&amp;blog=7696586&amp;post=15&amp;subd=sinea&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p> </p>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">#include &lt;iostream.h&gt;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">#include &lt;math.h&gt;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">#include &lt;time.h&gt;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">bool isPrime(int&amp; x)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">        if (x == 1 || (x % 2 == 0 &amp;&amp; x != 2)) return false;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>if(x % 3 == 0) return false;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">        for (int i = 3; i &lt;= sqrt(x); i += 2)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">            if (x % i == 0)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">                return false;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">        return true;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">int main()</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>cout &lt;&lt; &#8221; &#8212; GOLDBACH &#8212; &#8221; &lt;&lt; endl;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>int numar,ultim;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span></div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span></div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>bool gasit = false;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>cin &gt;&gt; numar;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>clock_t startTime = clock();</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>clock_t finTime;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>ultim = numar;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>if(numar &lt; 4)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return 0;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>for(int i=0; i&lt;=numar/2; i++)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>if(isPrime(i))</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>for(int j = ultim-1; j &gt;= numar/2; j-=2)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>if(isPrime(j) &amp;&amp; i+j == numar)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>cout &lt;&lt; &#8220;First : &#8221; &lt;&lt; i &lt;&lt; endl &lt;&lt; &#8220;Second : &#8221; &lt;&lt; j &lt;&lt; endl;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>i = numar;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>j = 0;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>else if(i+j &lt; numar)</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>ultim = j+1;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>break;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span></div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>finTime = clock();</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span></div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>cout &lt;&lt; finTime &lt;&lt; &#8221; -&gt; &#8221; &lt;&lt; startTime &lt;&lt; &#8220;ms&#8221; &lt;&lt; endl;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>cout &lt;&lt; &#8221; &#8211; - &#8211; - &#8211; - &#8211; &#8221; &lt;&lt; endl;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span></div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return 0;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">}</div>
<div>Goldbach for numbers between 4 and 2000000000 <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </div>
<div></div>
<div><span style="font-family:0;line-height:15px;">These are the number of ways to write an even number n as the sum of two primes (4 ≤ n ≤ 1,000,000);</span></div>
<div><img class="alignnone" title="Goldbach" src="http://upload.wikimedia.org/wikipedia/commons/7/7c/Goldbach-1000000.png" alt="" width="432" height="302" /></div>
<div>Runs in less than 1 second</div>
<div>Enjoy</div>
<div>#include &lt;iostream.h&gt;</div>
<div>#include &lt;math.h&gt;</div>
<div>#include &lt;time.h&gt;</div>
<div>bool isPrime(int&amp; x)</div>
<div>{</div>
<div>        if (x == 1 || (x % 2 == 0 &amp;&amp; x != 2)) return false;</div>
<div><span style="white-space:pre;"> </span>if(x % 3 == 0) return false;</div>
<div>        for (int i = 3; i &lt;= sqrt(x); i += 2)</div>
<div>            if (x % i == 0)</div>
<div>                return false;</div>
<div>        return true;</div>
<div>}</div>
<div>int main()</div>
<div>{</div>
<div><span style="white-space:pre;"> </span>cout &lt;&lt; &#8221; &#8212; GOLDBACH &#8212; &#8221; &lt;&lt; endl;</div>
<div><span style="white-space:pre;"> </span>int numar,ultim;</div>
<div><span style="white-space:pre;"> </span></div>
<div><span style="white-space:pre;"> </span>bool gasit = false;</div>
<div><span style="white-space:pre;"> </span>cin &gt;&gt; numar;</div>
<div><span style="white-space:pre;"> </span>clock_t startTime = clock();</div>
<div><span style="white-space:pre;"> </span>clock_t finTime;</div>
<div><span style="white-space:pre;"> </span>ultim = numar;</div>
<div><span style="white-space:pre;"> </span>if(numar &lt; 4)</div>
<div><span style="white-space:pre;"> </span>return 0;</div>
<div><span style="white-space:pre;"> </span>for(int i=0; i&lt;=numar/2; i++)</div>
<div><span style="white-space:pre;"> </span>{</div>
<div><span style="white-space:pre;"> </span>if(isPrime(i))</div>
<div><span style="white-space:pre;"> </span>{</div>
<div><span style="white-space:pre;"> </span>for(int j = ultim-1; j &gt;= numar/2; j-=2)</div>
<div><span style="white-space:pre;"> </span>{</div>
<div><span style="white-space:pre;"> </span>if(isPrime(j) &amp;&amp; i+j == numar)</div>
<div><span style="white-space:pre;"> </span>{</div>
<div><span style="white-space:pre;"> </span>cout &lt;&lt; &#8220;First : &#8221; &lt;&lt; i &lt;&lt; endl &lt;&lt; &#8220;Second : &#8221; &lt;&lt; j &lt;&lt; endl;</div>
<div><span style="white-space:pre;"> </span>i = numar;</div>
<div><span style="white-space:pre;"> </span>j = 0;</div>
<div><span style="white-space:pre;"> </span>}</div>
<div><span style="white-space:pre;"> </span>else if(i+j &lt; numar)</div>
<div><span style="white-space:pre;"> </span>{</div>
<div><span style="white-space:pre;"> </span>ultim = j+1;</div>
<div><span style="white-space:pre;"> </span>break;</div>
<div><span style="white-space:pre;"> </span>}</div>
<div><span style="white-space:pre;"> </span>}</div>
<div><span style="white-space:pre;"> </span>}</div>
<div><span style="white-space:pre;"> </span>}</div>
<div><span style="white-space:pre;"> </span></div>
<div><span style="white-space:pre;"> </span>finTime = clock();</div>
<div><span style="white-space:pre;"> </span></div>
<div><span style="white-space:pre;"> </span>cout &lt;&lt; finTime &lt;&lt; &#8221; -&gt; &#8221; &lt;&lt; startTime &lt;&lt; &#8220;ms&#8221; &lt;&lt; endl;</div>
<div><span style="white-space:pre;"> </span>cout &lt;&lt; &#8221; &#8211; - &#8211; - &#8211; - &#8211; &#8221; &lt;&lt; endl;</div>
<div><span style="white-space:pre;"> </span></div>
<div><span style="white-space:pre;"> </span>return 0;</div>
<div>}</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sinea.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sinea.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sinea.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sinea.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sinea.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sinea.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sinea.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sinea.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sinea.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sinea.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sinea.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sinea.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sinea.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sinea.wordpress.com/15/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sinea.wordpress.com&amp;blog=7696586&amp;post=15&amp;subd=sinea&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sinea.wordpress.com/2009/05/11/goldbachs-conjecture-made-simple-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e7dd8e0de54fd63f995aa3b9014d3fdd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sinea</media:title>
		</media:content>

		<media:content url="http://upload.wikimedia.org/wikipedia/commons/7/7c/Goldbach-1000000.png" medium="image">
			<media:title type="html">Goldbach</media:title>
		</media:content>
	</item>
		<item>
		<title>c++ recursive function for files</title>
		<link>http://sinea.wordpress.com/2009/05/10/c-recursive-function-for-files/</link>
		<comments>http://sinea.wordpress.com/2009/05/10/c-recursive-function-for-files/#comments</comments>
		<pubDate>Sun, 10 May 2009 21:06:28 +0000</pubDate>
		<dc:creator>sinea</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[c++ recursive files]]></category>

		<guid isPermaLink="false">http://sinea.wordpress.com/?p=6</guid>
		<description><![CDATA[something i wrote some months ago<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sinea.wordpress.com&amp;blog=7696586&amp;post=6&amp;subd=sinea&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Using a recursive function in c++ to search a file or folder using dirent.h <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>void renderFolder(char folder[])<br />
{<br />
<span style="white-space:pre;"> </span>DIR *director = opendir(folder);</p>
<p><span style="white-space:pre;"> </span>if(director)<br />
<span style="white-space:pre;"> </span>{<br />
<span style="white-space:pre;"> </span><span style="white-space:pre;"> </span>struct dirent *deCitit;<br />
<span style="white-space:pre;"> </span><span style="white-space:pre;"> </span>deCitit= readdir(director);<br />
<span style="white-space:pre;"> </span><span style="white-space:pre;"> </span>char *nume;</p>
<p><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span>while (deCitit=readdir(director))<br />
<span style="white-space:pre;"> </span><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span>{<br />
<span style="white-space:pre;"> </span><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span>nume = deCitit-&gt;d_name;<br />
<span style="white-space:pre;"> </span><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span>char newPath[512];</p>
<p><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span>/* </p>
<p>USE indicatorExtensie TO VERIFY IF EXTENSION IS .exe IN THIS CASE OR WE COULD SEARCH THE NAME OF THE FILE <br />
<span style="white-space:pre;"> </span><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span>*/</p>
<p><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span>char * indicatorExtensie;<br />
<span style="white-space:pre;"> </span><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span>indicatorExtensie = strstr(nume,&#8221;.exe&#8221;);</p>
<p><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span>strcpy(newPath, folder);<br />
<span style="white-space:pre;"> </span><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span>strcat(newPath , &#8220;\\&#8221;);<br />
<span style="white-space:pre;"> </span><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span>strcat(newPath , nume);</p>
<p><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span>/** NOW WE HAVE THE PATH TO THE FILE IN  newPath **/</p>
<p><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span>if(indicatorExtensie)<br />
<span style="white-space:pre;"> </span><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span>/** DO SOMETHING WITH  newPath &#8230;. ANYTHING  :) **/</p>
<p><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span>/** CONTINUE THE SEARCH <img src='http://s2.wp.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />   **/<br />
<span style="white-space:pre;"> </span><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span>renderFolder(newPath);<br />
<span style="white-space:pre;"> </span><span style="white-space:pre;"> </span><span style="white-space:pre;"> </span>}<br />
<span style="white-space:pre;"> </span>}<br />
}</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sinea.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sinea.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sinea.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sinea.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sinea.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sinea.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sinea.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sinea.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sinea.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sinea.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sinea.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sinea.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sinea.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sinea.wordpress.com/6/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sinea.wordpress.com&amp;blog=7696586&amp;post=6&amp;subd=sinea&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sinea.wordpress.com/2009/05/10/c-recursive-function-for-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e7dd8e0de54fd63f995aa3b9014d3fdd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sinea</media:title>
		</media:content>
	</item>
		<item>
		<title>Cu asta incep &#8230;</title>
		<link>http://sinea.wordpress.com/2009/05/10/cu-asta-incep/</link>
		<comments>http://sinea.wordpress.com/2009/05/10/cu-asta-incep/#comments</comments>
		<pubDate>Sun, 10 May 2009 20:50:38 +0000</pubDate>
		<dc:creator>sinea</dc:creator>
				<category><![CDATA[ce prost suna 'Uncategorized']]></category>

		<guid isPermaLink="false">http://sinea.wordpress.com/?p=3</guid>
		<description><![CDATA[Primul post &#8230; sant curios cat o sa scriu pe blogu&#8217; asta &#8230; nu ii dau mai mult de 2 saptamani .. )<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sinea.wordpress.com&amp;blog=7696586&amp;post=3&amp;subd=sinea&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Primul post &#8230; sant curios cat o sa scriu pe blogu&#8217; asta &#8230; nu ii dau mai mult de 2 saptamani .. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> )</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sinea.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sinea.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sinea.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sinea.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sinea.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sinea.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sinea.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sinea.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sinea.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sinea.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sinea.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sinea.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sinea.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sinea.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sinea.wordpress.com&amp;blog=7696586&amp;post=3&amp;subd=sinea&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sinea.wordpress.com/2009/05/10/cu-asta-incep/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e7dd8e0de54fd63f995aa3b9014d3fdd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sinea</media:title>
		</media:content>
	</item>
		<item>
		<title>Hello world!</title>
		<link>http://sinea.wordpress.com/2009/05/10/hello-world/</link>
		<comments>http://sinea.wordpress.com/2009/05/10/hello-world/#comments</comments>
		<pubDate>Sun, 10 May 2009 20:40:28 +0000</pubDate>
		<dc:creator>sinea</dc:creator>
				<category><![CDATA[ce prost suna 'Uncategorized']]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sinea.wordpress.com&amp;blog=7696586&amp;post=1&amp;subd=sinea&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Welcome to <a href="http://wordpress.com/">WordPress.com</a>. This is your first post. Edit or delete it and start blogging!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sinea.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sinea.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sinea.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sinea.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sinea.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sinea.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sinea.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sinea.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sinea.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sinea.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sinea.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sinea.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sinea.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sinea.wordpress.com/1/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sinea.wordpress.com&amp;blog=7696586&amp;post=1&amp;subd=sinea&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sinea.wordpress.com/2009/05/10/hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e7dd8e0de54fd63f995aa3b9014d3fdd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sinea</media:title>
		</media:content>
	</item>
	</channel>
</rss>
