<?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[Bubble Sort]]></title><description><![CDATA[<p>Hallöchen,</p>
<p>ich hab ein Programm für das Sortierverfahren &quot;Bubble Sort&quot;.<br />
Nun will ich aber, dass ich nicht die Zahlen einlese, sondern dass das Programm dies für mich macht. Angeblich geht dies mit dem folgenden Code:</p>
<pre><code>for (unsigned int i=0; i &lt; n; i++)
	A[i] = rand();
</code></pre>
<p>Wie bring ich den aber nun in dieses Programm hinein.<br />
Am ende will ich dann nämlich sehen, ob das Programm länger braucht (bzw. wie lange es braucht) für eine bestimmte Anzahl von Zahlen, die ich aber nicht alle selber von Hand eingeben will, weil das etwas lange dauert <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Eigentlich müsste es doch dorthin, wo es derzeit steht (ohne //) und die do-while schleife dafür weg, bzw umschreiben? Habs bisher net hinbekommen :xmas2:</p>
<p>Wäre super, wenn mir da jemand helfen könnte.</p>
<p>Gruß<br />
Rick</p>
<pre><code>C++
</code></pre>
<pre><code>#include &quot;stdafx.h&quot;
#include &lt;iostream&gt;
#include &lt;ctime&gt;
#include &lt;cstdlib&gt;
using namespace std;

void main() {
    const int max=100; 
    int n=0, zahl;
    int A[max]={0};
	int i,j, tmp;

	//for (unsigned int i=0; i &lt; n; i++)
	//A[i] = rand();

	do {                            // Einlesen der Daten
        cout &lt;&lt; &quot;Integer (0 Abbruch): &quot;;
        cin &gt;&gt; zahl;
        A[n] = zahl;
        if (zahl != 0) n++;    // Anzahl der Elemente
    } while (zahl !=0 &amp;&amp; n&lt;max);

	time_t vorher=time(NULL);

	// Sortieren
    for (int i=1; i &lt; n; i++)   // Durchläufe
        for (int j=n-1; j&gt;=i; j--) {// ein Durchlauf
            if (A[j-1] &gt; A[j]) { // vertauschen
                int tmp = A[j-1];
                A[j-1] = A[j];
                A[j] = tmp;
            }
        }
    for (int i= 0; i&lt;n ; i++)       // Ausgeben
        cout &lt;&lt; A[i] &lt;&lt; &quot; &quot;;

	time_t nachher=time(NULL);
	cout &lt;&lt; endl;

	cout &lt;&lt; &quot;Dauer: &quot; &lt;&lt; nachher-vorher &lt;&lt; &quot;sec&quot; &lt;&lt; endl;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/166938/bubble-sort</link><generator>RSS for Node</generator><lastBuildDate>Tue, 15 Sep 2026 15:36:27 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/166938.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 04 Dec 2006 15:26:11 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Bubble Sort on Mon, 04 Dec 2006 15:26:11 GMT]]></title><description><![CDATA[<p>Hallöchen,</p>
<p>ich hab ein Programm für das Sortierverfahren &quot;Bubble Sort&quot;.<br />
Nun will ich aber, dass ich nicht die Zahlen einlese, sondern dass das Programm dies für mich macht. Angeblich geht dies mit dem folgenden Code:</p>
<pre><code>for (unsigned int i=0; i &lt; n; i++)
	A[i] = rand();
</code></pre>
<p>Wie bring ich den aber nun in dieses Programm hinein.<br />
Am ende will ich dann nämlich sehen, ob das Programm länger braucht (bzw. wie lange es braucht) für eine bestimmte Anzahl von Zahlen, die ich aber nicht alle selber von Hand eingeben will, weil das etwas lange dauert <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Eigentlich müsste es doch dorthin, wo es derzeit steht (ohne //) und die do-while schleife dafür weg, bzw umschreiben? Habs bisher net hinbekommen :xmas2:</p>
<p>Wäre super, wenn mir da jemand helfen könnte.</p>
<p>Gruß<br />
Rick</p>
<pre><code>C++
</code></pre>
<pre><code>#include &quot;stdafx.h&quot;
#include &lt;iostream&gt;
#include &lt;ctime&gt;
#include &lt;cstdlib&gt;
using namespace std;

void main() {
    const int max=100; 
    int n=0, zahl;
    int A[max]={0};
	int i,j, tmp;

	//for (unsigned int i=0; i &lt; n; i++)
	//A[i] = rand();

	do {                            // Einlesen der Daten
        cout &lt;&lt; &quot;Integer (0 Abbruch): &quot;;
        cin &gt;&gt; zahl;
        A[n] = zahl;
        if (zahl != 0) n++;    // Anzahl der Elemente
    } while (zahl !=0 &amp;&amp; n&lt;max);

	time_t vorher=time(NULL);

	// Sortieren
    for (int i=1; i &lt; n; i++)   // Durchläufe
        for (int j=n-1; j&gt;=i; j--) {// ein Durchlauf
            if (A[j-1] &gt; A[j]) { // vertauschen
                int tmp = A[j-1];
                A[j-1] = A[j];
                A[j] = tmp;
            }
        }
    for (int i= 0; i&lt;n ; i++)       // Ausgeben
        cout &lt;&lt; A[i] &lt;&lt; &quot; &quot;;

	time_t nachher=time(NULL);
	cout &lt;&lt; endl;

	cout &lt;&lt; &quot;Dauer: &quot; &lt;&lt; nachher-vorher &lt;&lt; &quot;sec&quot; &lt;&lt; endl;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1186986</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1186986</guid><dc:creator><![CDATA[derRick]]></dc:creator><pubDate>Mon, 04 Dec 2006 15:26:11 GMT</pubDate></item><item><title><![CDATA[Reply to Bubble Sort on Mon, 04 Dec 2006 15:31:50 GMT]]></title><description><![CDATA[<p>Hallo!</p>
<p>Wenn du mit rand() Zufallszahlen erstellst, dann solltest du folgendes am Programm - Anfang nicht vergessen:</p>
<pre><code class="language-cpp">srand ((unsigned) time (0));
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1186994</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1186994</guid><dc:creator><![CDATA[life_drake]]></dc:creator><pubDate>Mon, 04 Dec 2006 15:31:50 GMT</pubDate></item><item><title><![CDATA[Reply to Bubble Sort on Mon, 04 Dec 2006 15:58:23 GMT]]></title><description><![CDATA[<p>derRick schrieb:</p>
<blockquote>
<pre><code class="language-cpp">const int max=100; 
    int n=0 /* Rest gekürzt */;
    int A[max]={0};

    /* Rest gekürzt */
    for (unsigned int i=0; i &lt; n; i++)
        A[i] = rand();
    /* Rest gekürzt */
</code></pre>
</blockquote>
<p>Beim Kopieren von Code sollte man auch stets ein wenig mitdenken, denn nicht jeder nennt seine Variablen wie Du. Wie groß ist das Array A? Und wie groß ist n? Und von wo bis wo zählt i? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>EDIT: Und &quot;habs bisher nicht hinbekommen&quot; ist eine denkbar schlechte Beschreibung dessen, <strong>was</strong> an dem geposteten Code nicht funktioniert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1187021</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1187021</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Mon, 04 Dec 2006 15:58:23 GMT</pubDate></item><item><title><![CDATA[Reply to Bubble Sort on Mon, 04 Dec 2006 16:02:57 GMT]]></title><description><![CDATA[<p>derRick schrieb:</p>
<blockquote>
<pre><code>void main() {
    const int max=100; 
    int n=0, zahl;
    int A[max]={0};
	int i,j, tmp;
    
	for (unsigned int i=0; i &lt; n; i++)
	A[i] = rand();
</code></pre>
</blockquote>
<p>Eine Schleife von 0 bis n mit n = 0. Dann überlege mal, wie oft die Schleife durchlaufen wird. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
<p>Gruß</p>
<p>Tntnet</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1187026</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1187026</guid><dc:creator><![CDATA[tntnet]]></dc:creator><pubDate>Mon, 04 Dec 2006 16:02:57 GMT</pubDate></item><item><title><![CDATA[Reply to Bubble Sort on Mon, 04 Dec 2006 16:03:51 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/9578">@tntnet</a>: Mensch verrat doch nicht gleich alles <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>*SCNR*</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1187027</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1187027</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Mon, 04 Dec 2006 16:03:51 GMT</pubDate></item><item><title><![CDATA[Reply to Bubble Sort on Mon, 04 Dec 2006 16:21:40 GMT]]></title><description><![CDATA[<p>aaaaaaaaaaaaaaaaaah SCHEI... äääh danke! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f60b.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_savoring_food"
      title=":yum:"
      alt="😋"
    /><br />
Schon dumm, wenn man den Wald vor lauter nackten Frauen nicht sieht, oder so ... :xmas1:</p>
<p>Nun klappts 1a.<br />
Dankeschön!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1187043</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1187043</guid><dc:creator><![CDATA[derRick]]></dc:creator><pubDate>Mon, 04 Dec 2006 16:21:40 GMT</pubDate></item></channel></rss>