<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Anfänger versucht zu sortieren.....]]></title><description><![CDATA[<p>Hallo<br />
ich möchte eingegebene Zahlen in ein Array eingeben. Das Array auf-- oder absteigend sortieren und in eine ListBox ausgeben. Leider komme ich nicht<br />
weiter. Also was mache ich falsch? Hier mein Code:</p>
<pre><code>x[0] = StrToInt (Edit1-&gt;Text);
x[1] = StrToInt (Edit2-&gt;Text);
x[2] = StrToInt (Edit5-&gt;Text);
x[3] = StrToInt (Edit7-&gt;Text);
x[4] = StrToInt (Edit8-&gt;Text);
x[5] = StrToInt (Edit9-&gt;Text);
x[6] = StrToInt (Edit10-&gt;Text);
x[7] = StrToInt (Edit11-&gt;Text);
x[8] = StrToInt (Edit12-&gt;Text);
x[9] = StrToInt (Edit13-&gt;Text);
x[10] = StrToInt (Edit14-&gt;Text);
x[11] = StrToInt (Edit15-&gt;Text);
x[12] = StrToInt (Edit16-&gt;Text);
x[13] = StrToInt (Edit17-&gt;Text);
x[14] = StrToInt (Edit18-&gt;Text);
x[15] = StrToInt (Edit19-&gt;Text);
x[16] = StrToInt (Edit20-&gt;Text);

for (i = 0; i &lt; 16; i++)
{

    for (j = i+1; j &lt; 17; j++)
    {

        if (x[i] &gt; x[j])
        {

                 hilf = x[i];
                 x[i] = x[j];
                 x[j] = hilf;
        }
    }
}

if (RadioButton1-&gt;Checked==true)// aufsteigend
{
ListBox1-&gt;Clear();
for (i = 0; i &lt; 16; i++)  { ListBox1-&gt;Items-&gt;Add(x[i]);}
}

if (RadioButton2-&gt;Checked==true)//absteigend
{
ListBox1-&gt;Clear();
for (i = 16; i &lt; 1; i--)  { ListBox1-&gt;Items-&gt;Add(x[i]);}
}

}
</code></pre>
<p>thx<br />
G-Kar</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/179113/anfänger-versucht-zu-sortieren</link><generator>RSS for Node</generator><lastBuildDate>Sat, 15 Aug 2026 12:31:19 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/179113.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 18 Apr 2007 15:47:36 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Anfänger versucht zu sortieren..... on Wed, 18 Apr 2007 15:47:36 GMT]]></title><description><![CDATA[<p>Hallo<br />
ich möchte eingegebene Zahlen in ein Array eingeben. Das Array auf-- oder absteigend sortieren und in eine ListBox ausgeben. Leider komme ich nicht<br />
weiter. Also was mache ich falsch? Hier mein Code:</p>
<pre><code>x[0] = StrToInt (Edit1-&gt;Text);
x[1] = StrToInt (Edit2-&gt;Text);
x[2] = StrToInt (Edit5-&gt;Text);
x[3] = StrToInt (Edit7-&gt;Text);
x[4] = StrToInt (Edit8-&gt;Text);
x[5] = StrToInt (Edit9-&gt;Text);
x[6] = StrToInt (Edit10-&gt;Text);
x[7] = StrToInt (Edit11-&gt;Text);
x[8] = StrToInt (Edit12-&gt;Text);
x[9] = StrToInt (Edit13-&gt;Text);
x[10] = StrToInt (Edit14-&gt;Text);
x[11] = StrToInt (Edit15-&gt;Text);
x[12] = StrToInt (Edit16-&gt;Text);
x[13] = StrToInt (Edit17-&gt;Text);
x[14] = StrToInt (Edit18-&gt;Text);
x[15] = StrToInt (Edit19-&gt;Text);
x[16] = StrToInt (Edit20-&gt;Text);

for (i = 0; i &lt; 16; i++)
{

    for (j = i+1; j &lt; 17; j++)
    {

        if (x[i] &gt; x[j])
        {

                 hilf = x[i];
                 x[i] = x[j];
                 x[j] = hilf;
        }
    }
}

if (RadioButton1-&gt;Checked==true)// aufsteigend
{
ListBox1-&gt;Clear();
for (i = 0; i &lt; 16; i++)  { ListBox1-&gt;Items-&gt;Add(x[i]);}
}

if (RadioButton2-&gt;Checked==true)//absteigend
{
ListBox1-&gt;Clear();
for (i = 16; i &lt; 1; i--)  { ListBox1-&gt;Items-&gt;Add(x[i]);}
}

}
</code></pre>
<p>thx<br />
G-Kar</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1268612</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1268612</guid><dc:creator><![CDATA[G-Kar]]></dc:creator><pubDate>Wed, 18 Apr 2007 15:47:36 GMT</pubDate></item><item><title><![CDATA[Reply to Anfänger versucht zu sortieren..... on Wed, 18 Apr 2007 16:46:21 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>Der Sortieralgorithmus (Z19 - Z33) sollte so auf jeden Fall funktionieren.</p>
<p>Anmerkung: Die Zuweisung der Editfelder ins Array ist nicht 1:1, also z.B. wird x[2] Editfeld 5 zugewiesen. Ob das so stimmt, musst Du wissen.</p>
<p>Kann sein, dass deine Anwendungen zwei Ausgaben möchte, aber ansonsten würde ich die zweite Ausgabe (absteigend) in einer else Anweisung schreiben - aber ob das für Dich sinnvoll ist, kann ich natürlich auch nicht wissen.</p>
<p>Was genau funktioniert denn Deiner Ansicht nach nicht?</p>
<p>Gruß<br />
Markus</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1268643</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1268643</guid><dc:creator><![CDATA[HMarkus]]></dc:creator><pubDate>Wed, 18 Apr 2007 16:46:21 GMT</pubDate></item><item><title><![CDATA[Reply to Anfänger versucht zu sortieren..... on Thu, 19 Apr 2007 07:38:32 GMT]]></title><description><![CDATA[<p>Ich vermute mal, dass du den guten alten &quot;Bubblesort&quot; implementieren wolltest, oder ?</p>
<p>du musst diese Vertauschoperation</p>
<p>if (x[i] &gt; x[j])<br />
{</p>
<p>hilf = x[i];<br />
x[i] = x[j];<br />
x[j] = hilf;<br />
}</p>
<p>solange durchführen, bis für das gesamten Array gilt: x[i] &lt; x[j]), erst dann ist es richtig sortiert. Also den Code in die Richtig erweitern:</p>
<p>bool unsortiert;</p>
<p>do {</p>
<p>unsortiert = false;</p>
<p>for .... Schleife über Array</p>
<p>if (x[i] &gt; x[j]) {<br />
x[i] = x[i] + x[j]; // mal ohne Hilfsvariable<br />
x[j] = x[i] - x[j];<br />
x[i] = x[i] - x[j];<br />
unsortiert= true;<br />
}</p>
<p>}<br />
while ( unsortiert )</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1268966</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1268966</guid><dc:creator><![CDATA[Datenhirsch]]></dc:creator><pubDate>Thu, 19 Apr 2007 07:38:32 GMT</pubDate></item><item><title><![CDATA[Reply to Anfänger versucht zu sortieren..... on Thu, 19 Apr 2007 09:16:45 GMT]]></title><description><![CDATA[<p>Es gibt mehrere Möglichkeiten den Bubblesort-Algo zu implementieren. Beide gezeigten sind richtig (das Vertauschen mit der Hilfsvariablen ist sogar besser!).</p>
<p>Aber es gibt einen Fehler bei der absteigend sortierten Liste - die Bedingung ist falsch, es muß</p>
<pre><code class="language-cpp">for (i = 16; i &gt;= 0; i--)
</code></pre>
<p>heißen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1269054</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1269054</guid><dc:creator><![CDATA[Th]]></dc:creator><pubDate>Thu, 19 Apr 2007 09:16:45 GMT</pubDate></item><item><title><![CDATA[Reply to Anfänger versucht zu sortieren..... on Fri, 20 Apr 2007 19:41:39 GMT]]></title><description><![CDATA[<p>boch mal thx für die schnellen Antworten. Die Sortierung hatte doch kleine Fehler. Ich hab mich auch dafür entschieden mit einem Eingabefeld und einer ListBox zu arbeiten.</p>
<p>Der funktionierende Code:</p>
<pre><code>for (int i = 0; i &lt; zaehler; i++)
{

      for (int j = 0; j &lt; zaehler-1; j++)
    {

        if (zahlen[j] &gt; zahlen[j+1])
        {

                 hilf = zahlen[j];
                 zahlen[j] = zahlen[j+1];
                 zahlen[j+1] = hilf;
        }
    }
}

if (RadioButton1-&gt;Checked==true)

{
ListBox1-&gt;Clear();    //aufsteigend
for (int a = 0; a &lt; zaehler; a++)  { ListBox1-&gt;Items-&gt;Add(zahlen[a]);}
}

if (RadioButton2-&gt;Checked==true)

{
ListBox1-&gt;Clear();
for (int a = zaehler-1; a &gt; -1; a--)  { ListBox1-&gt;Items-&gt;Add(zahlen[a]);}
}
</code></pre>
<p>mfg<br />
G-Kar</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1270232</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1270232</guid><dc:creator><![CDATA[G-Kar]]></dc:creator><pubDate>Fri, 20 Apr 2007 19:41:39 GMT</pubDate></item><item><title><![CDATA[Reply to Anfänger versucht zu sortieren..... on Mon, 23 Apr 2007 08:20:46 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>Noch ein Hinweis.<br />
Statt</p>
<pre><code class="language-cpp">hilf = zahlen[j];
zahlen[j] = zahlen[j+1];
zahlen[j+1] = hilf;
</code></pre>
<p>kann man auch</p>
<pre><code class="language-cpp">std::swap(zahlen[j], zahlen[j+1]);
</code></pre>
<p>schreiben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1271531</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1271531</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Mon, 23 Apr 2007 08:20:46 GMT</pubDate></item><item><title><![CDATA[Reply to Anfänger versucht zu sortieren..... on Mon, 23 Apr 2007 10:40:41 GMT]]></title><description><![CDATA[<p>Ich würde auf sowas ganz verzichten.<br />
Warum das Rad neu erfinden ?</p>
<pre><code class="language-cpp">vector &lt;int&gt; zahlen;
zahlen.push_back(StrToInt(Edit1-&gt;Text));
zahlen.push_back(StrToInt(Edit2-&gt;Text));
//*
if(RadioButton1-&gt;Checked) sort(zahlen.begin(),zahlen.end(),less&lt;int&gt;());
else sort(zahlen.begin(),zahlen.end(),greater&lt;int&gt;());
vector &lt;int&gt;::iterator it=zahlen.begin();
ListBox1-&gt;Clear();
while(it!=zahlen.end()) ListBox1-&gt;Items-&gt;Add(*it++);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1271628</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1271628</guid><dc:creator><![CDATA[sorter]]></dc:creator><pubDate>Mon, 23 Apr 2007 10:40:41 GMT</pubDate></item></channel></rss>