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

<channel>
	<title>Talk Binary &#187; source code</title>
	<atom:link href="http://talkbinary.com/tag/source-code/feed/" rel="self" type="application/rss+xml" />
	<link>http://talkbinary.com</link>
	<description>Programming Resources, Technology, Computers</description>
	<lastBuildDate>Mon, 06 Feb 2012 17:01:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Binary Search in C++</title>
		<link>http://talkbinary.com/uncategorized/binary-search-in-c/</link>
		<comments>http://talkbinary.com/uncategorized/binary-search-in-c/#comments</comments>
		<pubDate>Sun, 28 Dec 2008 08:53:55 +0000</pubDate>
		<dc:creator>Diego</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[binary search]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[container]]></category>
		<category><![CDATA[pseudo-code]]></category>
		<category><![CDATA[pseudocode]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[source code]]></category>

		<guid isPermaLink="false">http://talkbinary.com/?p=1393</guid>
		<description><![CDATA[Binary Search is a method to search through a sorted container in order to find a particular value. Remember that one &#8220;Guess the Number&#8221; game? Let&#8217;s look at the following scenario by applying the Binary Search algorithm in order for you to understand how Binary Search works. The Guessing Game Pick a number from 0<a class="moretag" href="http://talkbinary.com/uncategorized/binary-search-in-c/">&#160;&#160;Full Article&#8230;</a>
]]></description>
			<content:encoded><![CDATA[<p>Binary Search is a method to search through a sorted container in order to find a particular value.</p>
<p>Remember that one &#8220;Guess the Number&#8221; game? Let&#8217;s look at the following scenario by applying the Binary Search algorithm in order for you to understand how Binary Search works.</p>
<blockquote><h3 id="section-1">The Guessing Game</h3>
<p>Pick a number from 0 &#8211; 100 and depending on your guess, I&#8217;ll either say Correct, Higher, or Lower. What would you choose?</p>
<table>
<tr>
<td>0</td>
<td>1</td>
<td>&#8230;</td>
<td>49</td>
<td>50</td>
<td>51</td>
<td>&#8230;</td>
<td>99</td>
<td>100</td>
</tr>
</table>
<p>Well, 50 of course! Why? Best case you get it correct. Worst case you&#8217;ll either get a &#8220;Higher&#8221; or &#8220;Lower&#8221;. Now think about the following, if you got &#8220;Higher&#8221; you eliminated 0-49, or 51-100 if &#8220;Lower&#8221;, in other words, you eliminate HALF the possibilities.</p>
<table>
<tr>
<td>50</td>
<td>51</td>
<td>&#8230;</td>
<td>74</td>
<td>75</td>
<td>76</td>
<td>&#8230;</td>
<td>99</td>
<td>100</td>
</tr>
</table>
<p>Well, let&#8217;s say it was &#8220;Higher&#8221;. What would you guess after? 75. Since it&#8217;s in between 50 &#8211; 100. If you didn&#8217;t guess correctly, you&#8217;ll be facing the similar scenario as before. You&#8217;ll end up eliminating half the possibilities!
</p></blockquote>
<p><span id="more-1393"></span></p>
<h3 id="section-2">Binary Search Algorithm</h3>
<p>The following is the recursive implementation. </p>
<pre lang="c++">int binarysearch(vector <int> vec, int low, int high, int key)
{
    //Not found
    if ( low > high )
    {
          return -1;
    }

    //Finding the middle index between high and low
    int mid = (low + high)/2;

    //Returning the index if key is found
    if ( vec[mid] == key )
    {
          return mid;
    }
    //If middle index value is larger than our key, we search the lower half of the vector
    //else we search the upper half of the vector
    else if ( vec[mid] > key )
    {
          return binarysearch(vec, low, mid-1, key);
    }
    else
    {
          return binarysearch(vec, mid+1, high, key);
    }
}</pre>
<h3 id="section-3">Example of Binary Search</h3>
<p>Let&#8217;s say our container held the values 0-100 in its respective index values. Let&#8217;s say the value we are looking for is 57. </p>
<h4 id="section-4">First iteration</h4>
<table width="90%">
<tr>
<td>Index:</td>
<td>0</td>
<td>1</td>
<td>&#8230;</td>
<td>49</td>
<td>50</td>
<td>51</td>
<td>&#8230;</td>
<td>99</td>
<td>100</td>
</tr>
<tr>
<td>Value</td>
<td>0</td>
<td>1</td>
<td>&#8230;</td>
<td>49</td>
<td>50</td>
<td>51</td>
<td>&#8230;</td>
<td>99</td>
<td>100</td>
</tr>
<tr>
<td>Parameters:</td>
<td>low</td>
<td></td>
<td></td>
<td></td>
<td>mid</td>
<td></td>
<td></td>
<td></td>
<td>high</td>
</tr>
</table>
<p>50 < 57, so search through the upper half of our vector.</p>
<h4 id="section-5">Second iteration</h4>
<table width="90%">
<tr>
<td>Index:</td>
<td>51</td>
<td>52</td>
<td>&#8230;</td>
<td>74</td>
<td>75</td>
<td>76</td>
<td>&#8230;</td>
<td>99</td>
<td>100</td>
</tr>
<tr>
<td>Value</td>
<td>51</td>
<td>52</td>
<td>&#8230;</td>
<td>74</td>
<td>75</td>
<td>76</td>
<td>&#8230;</td>
<td>99</td>
<td>100</td>
</tr>
<tr>
<td>Parameters:</td>
<td>low</td>
<td></td>
<td></td>
<td></td>
<td>mid</td>
<td></td>
<td></td>
<td></td>
<td>high</td>
</tr>
</table>
<p>75 > 57, so search through the lower half of our vector.</p>
<h4 id="section-6">Third iteration</h4>
<table width="90%">
<tr>
<td>Index:</td>
<td>51</td>
<td>52</td>
<td>&#8230;</td>
<td>62</td>
<td>63</td>
<td>64</td>
<td>&#8230;</td>
<td>73</td>
<td>74</td>
</tr>
<tr>
<td>Value</td>
<td>51</td>
<td>52</td>
<td>&#8230;</td>
<td>62</td>
<td>63</td>
<td>64</td>
<td>&#8230;</td>
<td>73</td>
<td>74</td>
</tr>
<tr>
<td>Parameters:</td>
<td>low</td>
<td></td>
<td></td>
<td></td>
<td>mid</td>
<td></td>
<td></td>
<td></td>
<td>high</td>
</tr>
</table>
<p>63 > 57, so search through the lower half of our vector.</p>
<h4 id="section-7">Fourth iteration</h4>
<table width="90%">
<tr>
<td>Index:</td>
<td>51</td>
<td>52</td>
<td>&#8230;</td>
<td>56</td>
<td>57</td>
<td>58</td>
<td>&#8230;</td>
<td>61</td>
<td>62</td>
</tr>
<tr>
<td>Value</td>
<td>51</td>
<td>52</td>
<td>&#8230;</td>
<td>56</td>
<td>57</td>
<td>58</td>
<td>&#8230;</td>
<td>61</td>
<td>62</td>
</tr>
<tr>
<td>Parameters:</td>
<td>low</td>
<td></td>
<td></td>
<td></td>
<td>mid</td>
<td></td>
<td></td>
<td></td>
<td>high</td>
</tr>
</table>
<p>57 == 57!</p>
]]></content:encoded>
			<wfw:commentRss>http://talkbinary.com/uncategorized/binary-search-in-c/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Game Source Available</title>
		<link>http://talkbinary.com/programming/opengl/game-source-available/</link>
		<comments>http://talkbinary.com/programming/opengl/game-source-available/#comments</comments>
		<pubDate>Fri, 15 Aug 2008 06:46:19 +0000</pubDate>
		<dc:creator>Diego</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[game source]]></category>
		<category><![CDATA[make your own game]]></category>
		<category><![CDATA[modify game]]></category>
		<category><![CDATA[open source games]]></category>
		<category><![CDATA[source code]]></category>
		<category><![CDATA[video game]]></category>

		<guid isPermaLink="false">http://talkbinary.com/?p=639</guid>
		<description><![CDATA[Just wanted to keep everyone up to date and let you all know that the source code for the Piranha Plant, Wario, and Coin Game has been posted to the forums. Go ahead and give it a try, it will be a great experience to see what was put into making that simple game. Make<a class="moretag" href="http://talkbinary.com/programming/opengl/game-source-available/">&#160;&#160;Full Article&#8230;</a>
]]></description>
			<content:encoded><![CDATA[<p>Just wanted to keep everyone up to date and let you all know that the source code for the Piranha Plant, Wario, and Coin Game has been posted to the forums.</p>
<p><center><img class="alignnone size-medium wp-image-640" title="source" src="http://talkbinary.com/wp-content/uploads/2008/08/source.png"  /></center></p>
<p>Go ahead and give it a try, it will be a great experience to see what was put into making that simple game. Make a modification, or change it completely&#8230; you are free to do what you like with it.</p>
<p>Just as a reminder, Diego&#8217;s Pong Game will soon have another release along with source code. So stay tuned so you can take a look at the work that it takes to make a simple pong game. I know I&#8217;m waiting for it! </p>
<p><strong>Here is the link to the source:</strong><br />
<a href="http://talkbinary.com/forums/index.php?topic=61.0">Piranha Plant, Wario, and Coin Game Source</a> </p>
<p><strong>Here is how to set up your environment</strong><br />
Setting up your environment is relatively easy with the following tutorial.<br />
<a href="http://talkbinary.com/2008/08/codeblocks-with-sdl-support/">Codeblocks with SDL support</a></p>
<p>Enjoy! </p>
]]></content:encoded>
			<wfw:commentRss>http://talkbinary.com/programming/opengl/game-source-available/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Classic Pong</title>
		<link>http://talkbinary.com/programming/game-development/classic-pong/</link>
		<comments>http://talkbinary.com/programming/game-development/classic-pong/#comments</comments>
		<pubDate>Thu, 07 Aug 2008 17:04:13 +0000</pubDate>
		<dc:creator>Diego</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[Download]]></category>
		<category><![CDATA[learn]]></category>
		<category><![CDATA[make games]]></category>
		<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[pong]]></category>
		<category><![CDATA[sdl]]></category>
		<category><![CDATA[source code]]></category>

		<guid isPermaLink="false">http://talkbinary.com/?p=541</guid>
		<description><![CDATA[I&#8217;m releasing a preview of my Pong game. This is simply the first release, the second release should be the final. So far it took me about an hour to create. Not bad eh? You too will soon be able to make games like these so stick around so you can also be proficient in<a class="moretag" href="http://talkbinary.com/programming/game-development/classic-pong/">&#160;&#160;Full Article&#8230;</a>
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m releasing a preview of my Pong game. This is simply the first release, the second release should be the final. So far it took me about an hour to create. Not bad eh? You too will soon be able to make games like these so stick around so you can also be proficient in Talking Binary!</p>
<p><center><a href="http://talkbinary.com/wp-content/uploads/2008/08/pong.jpg"><img src="http://talkbinary.com/wp-content/uploads/2008/08/pong-300x232.jpg" alt="" title="pong" width="300" height="232" class="alignnone size-medium wp-image-542" /></a></center></p>
<p>For now the velocity of the ball is constant. I plan on changing that on my second release so its possible to beat the computer. </p>
<p>This was created using CodeBlocks and an OpenGL/SDL package from a friend of mine. So, soon once I believe the code is user friendly, I&#8217;ll release it so anyone can learn and create your own game! Don&#8217;t worry, it isn&#8217;t difficult. You use C++ and OpenGL/SDL handle all the graphics for you.</p>
<p><a href="http://talkbinary.com/forums/index.php?topic=59.0">Download and comment on the game here. </a></p>
<p>Controls: You move up and down with W and S.</p>
]]></content:encoded>
			<wfw:commentRss>http://talkbinary.com/programming/game-development/classic-pong/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced

Served from: talkbinary.com @ 2012-02-11 20:15:50 -->
