<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: 6.4 &#8212; Sorting an array using selection sort</title>
	<atom:link href="http://www.learncpp.com/cpp-tutorial/64-sorting-an-array-using-selection-sort/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.learncpp.com/cpp-tutorial/64-sorting-an-array-using-selection-sort/</link>
	<description></description>
	<lastBuildDate>Wed, 08 Sep 2010 10:51:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: equu</title>
		<link>http://www.learncpp.com/cpp-tutorial/64-sorting-an-array-using-selection-sort/comment-page-1/#comment-84984</link>
		<dc:creator>equu</dc:creator>
		<pubDate>Wed, 19 May 2010 15:57:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/64-sorting-an-array-using-selection-sort/#comment-84984</guid>
		<description>My 2ct:

&lt;pre&gt;
#include &lt;algorithm&gt; // for swap
#include &lt;iostream&gt;

int main() {
    using namespace std;

    const int nSize = 6;
    int anArray[nSize] = { 30, 60, 20, 50, 40, 10 };

    for (int i = 0; i &lt; nSize; i++) {
        for (int j = i + 1; j &lt; nSize; j++) {
            if (anArray[j] &lt; anArray[i]) {
                swap(anArray[i], anArray[j]);
            }
        }
    }

    for (int i = 0; i &lt; nSize; i++) {
        cout &lt;&lt; anArray[i] &lt;&lt; &quot; &quot;;
    }

    cout &lt;&lt; endl;

    return 0;
}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>My 2ct:</p>
<pre>
#include &lt;algorithm&gt; // for swap
#include &lt;iostream&gt;

int main() {
    using namespace std;

    const int nSize = 6;
    int anArray[nSize] = { 30, 60, 20, 50, 40, 10 };

    for (int i = 0; i &lt; nSize; i++) {
        for (int j = i + 1; j &lt; nSize; j++) {
            if (anArray[j] &lt; anArray[i]) {
                swap(anArray[i], anArray[j]);
            }
        }
    }

    for (int i = 0; i &lt; nSize; i++) {
        cout &lt;&lt; anArray[i] &lt;&lt; &quot; &quot;;
    }

    cout &lt;&lt; endl;

    return 0;
}
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: amit mago</title>
		<link>http://www.learncpp.com/cpp-tutorial/64-sorting-an-array-using-selection-sort/comment-page-1/#comment-84254</link>
		<dc:creator>amit mago</dc:creator>
		<pubDate>Thu, 06 May 2010 19:38:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/64-sorting-an-array-using-selection-sort/#comment-84254</guid>
		<description>sir  i want tjhe code of insert a new element in array in c  and please
little explain it too</description>
		<content:encoded><![CDATA[<p>sir  i want tjhe code of insert a new element in array in c  and please<br />
little explain it too</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: linus</title>
		<link>http://www.learncpp.com/cpp-tutorial/64-sorting-an-array-using-selection-sort/comment-page-1/#comment-80681</link>
		<dc:creator>linus</dc:creator>
		<pubDate>Tue, 16 Mar 2010 16:19:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/64-sorting-an-array-using-selection-sort/#comment-80681</guid>
		<description>// array.cpp : Defines the entry point for the console application.
//

#include &quot;stdafx.h&quot;
#include 

int main()
{
	using namespace std;
	const int cNumberOfElements=6;
	int anScores[cNumberOfElements]={30,60,20,50,40,10};

	for (int i=0;i&lt;cNumberOfElements-1;i++)
	{
		for (int j=i+1;j&lt;cNumberOfElements;j++)
		{
			if (anScores[i]&lt;anScores[j]) swap(anScores[i],anScores[j]);
		}
	}
	cout &lt;&lt;&quot;arranged in descending order&quot;&lt;&lt;endl;
	for (int i=0; i&lt;cNumberOfElements;i++)
	{
		cout&lt;&lt;anScores[i]&lt;&lt;&quot;\t&quot;;
	}
	return 0;
}</description>
		<content:encoded><![CDATA[<p>// array.cpp : Defines the entry point for the console application.<br />
//</p>
<p>#include &#8220;stdafx.h&#8221;<br />
#include </p>
<p>int main()<br />
{<br />
	using namespace std;<br />
	const int cNumberOfElements=6;<br />
	int anScores[cNumberOfElements]={30,60,20,50,40,10};</p>
<p>	for (int i=0;i&lt;cNumberOfElements-1;i++)<br />
	{<br />
		for (int j=i+1;j&lt;cNumberOfElements;j++)<br />
		{<br />
			if (anScores[i]&lt;anScores[j]) swap(anScores[i],anScores[j]);<br />
		}<br />
	}<br />
	cout &lt;&lt;&quot;arranged in descending order&quot;&lt;&lt;endl;<br />
	for (int i=0; i&lt;cNumberOfElements;i++)<br />
	{<br />
		cout&lt;&lt;anScores[i]&lt;&lt;&quot;\t&quot;;<br />
	}<br />
	return 0;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Louisawasjerry</title>
		<link>http://www.learncpp.com/cpp-tutorial/64-sorting-an-array-using-selection-sort/comment-page-1/#comment-78143</link>
		<dc:creator>Louisawasjerry</dc:creator>
		<pubDate>Wed, 10 Feb 2010 14:20:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/64-sorting-an-array-using-selection-sort/#comment-78143</guid>
		<description>results obtain 
10 30
20 50
30 50
40 50
50 50</description>
		<content:encoded><![CDATA[<p>results obtain<br />
10 30<br />
20 50<br />
30 50<br />
40 50<br />
50 50</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Louisawasjerry</title>
		<link>http://www.learncpp.com/cpp-tutorial/64-sorting-an-array-using-selection-sort/comment-page-1/#comment-78142</link>
		<dc:creator>Louisawasjerry</dc:creator>
		<pubDate>Wed, 10 Feb 2010 14:17:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/64-sorting-an-array-using-selection-sort/#comment-78142</guid>
		<description>#include
using namespace std;

int main()
{
	const int nSize=5;
	int anArray[nSize]={30, 50, 20, 10, 40};
	//cout&lt;&lt;anArray[nSize]&lt;&lt;endl;
	
	for(int Indexzero=0;Indexzero&lt;nSize;Indexzero++)
	{
		int nSmallestIndex=Indexzero;
		//cout&lt;&lt;anArray[nSmallestIndex];
		for(int nCurrentIndex=Indexzero;nCurrentIndex&lt;nSize;nCurrentIndex++)
		{
			if(anArray[nCurrentIndex]&lt;anArray[nSmallestIndex])
				nSmallestIndex=nCurrentIndex;
				//cout&lt;&lt;anArray[nSmallestIndex];
		}
		swap(anArray[Indexzero],anArray[nSmallestIndex]);
	
		cout&lt;&lt;anArray[Indexzero]&lt;&lt; &quot; &quot;&lt;&lt;anArray[nSmallestIndex]&lt;&lt;endl;
		cout&lt;&lt;endl;
	}
	
system(&quot;pause&quot;);
return 0;
}



could anyone explain to me, please
results obtain 10 30
               20 50
               30 50 
               40 50
               50 50
in my second for loop, i leave for int nCurrentIndex=Indexzero instead of  int nCurrentIndex=Indexzero+1, but i still get the results. why?</description>
		<content:encoded><![CDATA[<p>#include<br />
using namespace std;</p>
<p>int main()<br />
{<br />
	const int nSize=5;<br />
	int anArray[nSize]={30, 50, 20, 10, 40};<br />
	//cout&lt;&lt;anArray[nSize]&lt;&lt;endl;</p>
<p>	for(int Indexzero=0;Indexzero&lt;nSize;Indexzero++)<br />
	{<br />
		int nSmallestIndex=Indexzero;<br />
		//cout&lt;&lt;anArray[nSmallestIndex];<br />
		for(int nCurrentIndex=Indexzero;nCurrentIndex&lt;nSize;nCurrentIndex++)<br />
		{<br />
			if(anArray[nCurrentIndex]&lt;anArray[nSmallestIndex])<br />
				nSmallestIndex=nCurrentIndex;<br />
				//cout&lt;&lt;anArray[nSmallestIndex];<br />
		}<br />
		swap(anArray[Indexzero],anArray[nSmallestIndex]);</p>
<p>		cout&lt;&lt;anArray[Indexzero]&lt;&lt; &quot; &quot;&lt;&lt;anArray[nSmallestIndex]&lt;&lt;endl;<br />
		cout&lt;&lt;endl;<br />
	}</p>
<p>system(&quot;pause&quot;);<br />
return 0;<br />
}</p>
<p>could anyone explain to me, please<br />
results obtain 10 30<br />
               20 50<br />
               30 50<br />
               40 50<br />
               50 50<br />
in my second for loop, i leave for int nCurrentIndex=Indexzero instead of  int nCurrentIndex=Indexzero+1, but i still get the results. why?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Louisawasjerry</title>
		<link>http://www.learncpp.com/cpp-tutorial/64-sorting-an-array-using-selection-sort/comment-page-1/#comment-78104</link>
		<dc:creator>Louisawasjerry</dc:creator>
		<pubDate>Tue, 09 Feb 2010 16:32:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/64-sorting-an-array-using-selection-sort/#comment-78104</guid>
		<description>hi 
i m new to c++
could any one explain to me that how is this for for loops work

1)for (int nStartIndex = 0; nStartIndex &lt; nSize; nStartIndex++)

   
2)for(int nCurrentIndex = nStartIndex + 1; nCurrentIndex &lt; nSize; nCurrentIndex++)
  

thank</description>
		<content:encoded><![CDATA[<p>hi<br />
i m new to c++<br />
could any one explain to me that how is this for for loops work</p>
<p>1)for (int nStartIndex = 0; nStartIndex &lt; nSize; nStartIndex++)</p>
<p>2)for(int nCurrentIndex = nStartIndex + 1; nCurrentIndex &lt; nSize; nCurrentIndex++)</p>
<p>thank</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zach</title>
		<link>http://www.learncpp.com/cpp-tutorial/64-sorting-an-array-using-selection-sort/comment-page-1/#comment-76476</link>
		<dc:creator>Zach</dc:creator>
		<pubDate>Fri, 15 Jan 2010 03:32:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/64-sorting-an-array-using-selection-sort/#comment-76476</guid>
		<description>Disregard that. I figured it out. Upon further examination I realized that if you don&#039;t continually check against your hold value, the last value that evaluated as &quot;true&quot; gets swapped, in this case 40. Had it been checking against nSmallestIndex, which gets incrementally smaller with each check, the loop would be checking 40 &lt; 10 rather than 40 &lt; 50. For the record, this is a hard concept to grab when your asked to write one off the top of your head lol. I hope I get quicker with this stuff.</description>
		<content:encoded><![CDATA[<p>Disregard that. I figured it out. Upon further examination I realized that if you don&#8217;t continually check against your hold value, the last value that evaluated as &#8220;true&#8221; gets swapped, in this case 40. Had it been checking against nSmallestIndex, which gets incrementally smaller with each check, the loop would be checking 40 &lt; 10 rather than 40 &lt; 50. For the record, this is a hard concept to grab when your asked to write one off the top of your head lol. I hope I get quicker with this stuff.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zach</title>
		<link>http://www.learncpp.com/cpp-tutorial/64-sorting-an-array-using-selection-sort/comment-page-1/#comment-76474</link>
		<dc:creator>Zach</dc:creator>
		<pubDate>Fri, 15 Jan 2010 02:58:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/64-sorting-an-array-using-selection-sort/#comment-76474</guid>
		<description>I am definitely new to programming, but so far I&#039;m understanding everything reasonably well. I do have one question though. If you are re-initializing &quot;nSmallestIndex&quot; to a value of &quot;nStartIndex&quot; each time, why do you use &quot;nSmallestIndex&quot; in this part of your loop? &lt;pre&gt;if (anArray[nCurrentIndex] &lt; anArray[nSmallestIndex])&lt;!--formatted--&gt;&lt;/pre&gt; If the purpose of &quot;nSmallestIndex&quot; is just to temporarily hold the smallest index whilst you search the rest, wouldn&#039;t it make more sense just to use &quot;nStartIndex&quot; and not bother giving &quot;nSmallestIndex&quot; a value of anything when it&#039;s initialized, thus using &quot;nSmallestIndex&quot; &lt;strong&gt;Only&lt;/strong&gt; as a temp holding place? I hope this is clear, I&#039;m not a C++ pro like some of you. It just took me a while to understand it because of this seemingly unnecessary assignment. Please let me know if there is a good reason for doing so. Thanks -Zach</description>
		<content:encoded><![CDATA[<p>I am definitely new to programming, but so far I&#8217;m understanding everything reasonably well. I do have one question though. If you are re-initializing &#8220;nSmallestIndex&#8221; to a value of &#8220;nStartIndex&#8221; each time, why do you use &#8220;nSmallestIndex&#8221; in this part of your loop?
<pre>if (anArray[nCurrentIndex] &lt; anArray[nSmallestIndex])<!--formatted--></pre>
<p> If the purpose of &#8220;nSmallestIndex&#8221; is just to temporarily hold the smallest index whilst you search the rest, wouldn&#8217;t it make more sense just to use &#8220;nStartIndex&#8221; and not bother giving &#8220;nSmallestIndex&#8221; a value of anything when it&#8217;s initialized, thus using &#8220;nSmallestIndex&#8221; <strong>Only</strong> as a temp holding place? I hope this is clear, I&#8217;m not a C++ pro like some of you. It just took me a while to understand it because of this seemingly unnecessary assignment. Please let me know if there is a good reason for doing so. Thanks -Zach</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Petey</title>
		<link>http://www.learncpp.com/cpp-tutorial/64-sorting-an-array-using-selection-sort/comment-page-1/#comment-76222</link>
		<dc:creator>Petey</dc:creator>
		<pubDate>Mon, 11 Jan 2010 22:34:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/64-sorting-an-array-using-selection-sort/#comment-76222</guid>
		<description>hello, i was wondering how swap works since you&#039;re passing an argument by value, not reference, or am i missing something? just wondering, that&#039;s all. great tutorials by the way</description>
		<content:encoded><![CDATA[<p>hello, i was wondering how swap works since you&#8217;re passing an argument by value, not reference, or am i missing something? just wondering, that&#8217;s all. great tutorials by the way</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew</title>
		<link>http://www.learncpp.com/cpp-tutorial/64-sorting-an-array-using-selection-sort/comment-page-1/#comment-75866</link>
		<dc:creator>Andrew</dc:creator>
		<pubDate>Wed, 06 Jan 2010 18:38:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/64-sorting-an-array-using-selection-sort/#comment-75866</guid>
		<description>never mind, i got my code to work. the problem wasnt with my output part of the function, i wrote: nCurrentIndex = nSmallestIndex, instead of the other way around.</description>
		<content:encoded><![CDATA[<p>never mind, i got my code to work. the problem wasnt with my output part of the function, i wrote: nCurrentIndex = nSmallestIndex, instead of the other way around.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
