<?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>entroducing.com &#187; Programming</title>
	<atom:link href="http://www.entroducing.com/view/tag/programming/feed" rel="self" type="application/rss+xml" />
	<link>http://www.entroducing.com</link>
	<description>to prove that i have too much time</description>
	<lastBuildDate>Sun, 15 May 2011 06:00:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Printing out active threads in java</title>
		<link>http://www.entroducing.com/view/printing-out-active-threads-in-java</link>
		<comments>http://www.entroducing.com/view/printing-out-active-threads-in-java#comments</comments>
		<pubDate>Sat, 20 Feb 2010 07:41:30 +0000</pubDate>
		<dc:creator>Benny</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[threads]]></category>

		<guid isPermaLink="false">http://www.entroducing.com/?p=157</guid>
		<description><![CDATA[Here&#8217;s the code snippets to display the number of running threads in your java program. It&#8217;s good to use it to track your resources. int activeCount = Thread.activeCount(); System.out.println(&#38;quot;total active = &#38;quot; + activeCount); Thread[] threads = new Thread[activeCount]; Thread.enumerate(threads); System.out.println(&#38;quot;before&#38;quot;); for (int j=0; j&#38;lt;threads.length; j++) { System.out.println(threads[j].toString()); } //run your classes Benny benny = new Benny(); [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s the code snippets to display the number of running threads in your java program.</p>
<p>It&#8217;s good to use it to track your resources.</p>
<pre class="brush: java">
int activeCount = Thread.activeCount();
System.out.println(&amp;quot;total active = &amp;quot; + activeCount);
Thread[] threads = new Thread[activeCount];
Thread.enumerate(threads);

System.out.println(&amp;quot;before&amp;quot;);
for (int j=0; j&amp;lt;threads.length; j++) {
 System.out.println(threads[j].toString());
}

//run your classes
Benny benny = new Benny();

activeCount = Thread.activeCount();
System.out.println(&amp;quot;total active = &amp;quot; + activeCount);

threads = new Thread[activeCount];
System.out.println(&amp;quot;after&amp;quot;);
Thread.enumerate(threads);
for (int i=0; i&amp;lt;threads.length; i++) {
 System.out.println(threads[i].toString());
}
</pre>
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.entroducing.com%2Fview%2Fprinting-out-active-threads-in-java&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>]]></content:encoded>
			<wfw:commentRss>http://www.entroducing.com/view/printing-out-active-threads-in-java/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Array sorting problem posted from hardwarezone</title>
		<link>http://www.entroducing.com/view/some-array-sorting-problem-posted-from-hardwarezone</link>
		<comments>http://www.entroducing.com/view/some-array-sorting-problem-posted-from-hardwarezone#comments</comments>
		<pubDate>Sat, 21 Nov 2009 17:46:11 +0000</pubDate>
		<dc:creator>Benny</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.entroducing.com/?p=129</guid>
		<description><![CDATA[Saw this challenging question posted in the hardwarezone forum on sorting an array with one for loop without using array list. The question is This is a simple programming question...very simple and short question, but its really hard to solve.. Anyone who could do it, you are god of programming. Given an array of random [...]]]></description>
			<content:encoded><![CDATA[<p>Saw <a href="http://forums.hardwarezone.com.sg/showthread.php?t=2566016">this challenging question</a> posted in the hardwarezone forum on sorting an array with<strong> one for loop</strong> without using array list.</p>
<p>The question is</p>
<pre>
<pre><strong><span id="intelliTXT">This is a simple programming question...very simple and short question, but its really hard to solve..</span>
<span id="intelliTXT">Anyone who could do it, you are god of programming. </span>

<span id="intelliTXT"> Given an array of random numbers let say..</span>

<span id="intelliTXT"> arrayX = {15, 20, 35, 45, 10, 40, 1, 3, 45};You are supposed to use ONLY ONE loop to swap the above into the following:</span>
<span id="intelliTXT"> arrayX = {15, 20, 3, 1, 10, 40, 45, 35, 45};</span>

<span id="intelliTXT"> NOTE: The purpose of your loop is to move all digits &lt; 25 from the right hand side to the left side, and move all digits &gt;= 25 to the right side. You can't sort the array but to use a single loop to scan the array from left and scan the array from right...and do the necessary swapping.</span>

<span id="intelliTXT"> You can try do it with C, C++...etc..</span>
<span id="intelliTXT"> Not easy as it seems to be!</span></strong>
</pre>
</pre>
<p>Since the night is still young, I took some time to sit down and figure out the solution.</p>
<p><span id="more-129"></span></p>
<p>There are some answers posted in that thread but their answers could not get the exact output out.</p>
<p>One forumer pointed out to have scan each element and put those &lt; 25 into one array and those =&gt; into another. This solution can work&#8230; but doesnt output that answer.</p>
<p>Here&#8217;s my solution in PHP.</p>
<pre class="brush: php">
&amp;lt;?php

    $array1 = array(15, 20, 35, 45, 10, 40, 1, 3, 45);
    $array2 = $array1;
    $j = sizeof($array2)-1;

    for ($i=0;$i&amp;lt;$j;$i++) {
      if ($array1[$i]&amp;gt;$array2[$j]){
      	if ($array1[$i]&amp;gt;25){
      		$array2[$i] = $array1[$j];
      		$array2[$j] = $array1[$i];
      		$array1 = $array2;
      		$j--;
      	}
      }else{
      	$j--;
      }
       print_r($array2);
       echo (&amp;quot;&amp;lt;br/&amp;gt;&amp;quot;);
    }

?&amp;gt;
</pre>
<p>I upload the php in my site. <a href="http://www.entroducing.com/tutorial/arraysort/arraysort.php">You can see the output here</a>.</p>
<p><strong>Explanation</strong></p>
<ol>
<li>Duplicate the array</li>
<li>Compare first element of that array with the last element of the second array. The exit condition of the for loop is when the the comparison of the position of both arrays meet.</li>
<li>If first element &gt; last element, we then further check if it&#8217;s &gt; 25. if yes, we swap them.</li>
<li>If not, we skip to next element in first array but the last element in second array still remains.</li>
</ol>
<p>That&#8217;s it! If you can further improve the codes. Please feel free to comment. Cheers.</p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.entroducing.com%2Fview%2Fsome-array-sorting-problem-posted-from-hardwarezone&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>]]></content:encoded>
			<wfw:commentRss>http://www.entroducing.com/view/some-array-sorting-problem-posted-from-hardwarezone/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

