<?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[Blubblesort Ausgabe]]></title><description><![CDATA[<p>Hi Leute,</p>
<p>bin noch blutiger Anfänger in C++ und grade am Lernen. Meine aktuelle Aufgabe ist es, einen einfachen Sortieralgo Anhand von Bubblesort zu machen. Dabei ist alles in einer Klasse gekapselt.</p>
<p>Mittlerweile funktioniert das schon ziemlich gut. Das einzige Problem welches ich habe, dass ich die Zwischenschritte ausgeben muss. Dabei hab ich mir einfach einen integer als flag definiert und diesen einfach auf 0 ändere wenn nichts passiert ist. Ich soll nun 9 3 5 6 1 7 2 0 8 4 sortieren. Meine Ausgabe lautet:</p>
<blockquote>
<p>9 3 5 6 1 7 2 0 8 4<br />
Sortiere ...</p>
<ol>
<li>3 5 6 1 7 2 0 8 4 9</li>
<li>3 5 1 6 2 0 7 4 8 9</li>
<li>3 1 5 2 0 6 4 7 8 9</li>
<li>1 3 2 0 5 4 6 7 8 9</li>
<li>1 2 0 3 4 5 6 7 8 9</li>
<li>1 0 2 3 4 5 6 7 8 9</li>
<li>0 1 2 3 4 5 6 7 8 9</li>
<li>0 1 2 3 4 5 6 7 8 9<br />
Sortierte Liste:<br />
0 1 2 3 4 5 6 7 8 9</li>
</ol>
</blockquote>
<p>Funktioniert alles bestens, aber ich hab halt den letzten Schritt doppelt ausgegeben. Ist ja auch klar. Davor hatte sich noch etwas geändert also läuft er noch einmal durch, dann ist keine änderung mehr vorhanden und es wird abgebrochen. In der Aufgabenstellung wird nun aber die Zeile <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f60e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--smiling_face_with_sunglasses"
      title="8)"
      alt="😎"
    /> nicht mehr ausgeben. Hat jemand eine Idee, wie ich das implementieren kann?</p>
<p>Vielen Dank!!!</p>
<pre><code>#include&lt;iostream&gt;
#include&quot;Bubblesort.h&quot;
using namespace std;

void Bubblesort::sort( int *array, int size )
{
  int flag=1; int zaehler=0;

  print();
  cout &lt;&lt; endl;
  cout &lt;&lt; &quot;Sortiere ...&quot; &lt;&lt; endl;
  cout &lt;&lt; endl;

    for(int i = 0; i &lt; size -1 &amp;&amp; flag; ++i)
    {
		flag=0;
		for (int j=0; j &lt; size -i -1; j++) 
		{
			// check ob kleiner als vorgänger
			if (A[j] &gt; A[j + 1])
			{	  
				// Werte vertauschen
				swap(j);		
				// es wurde etwas verändert
				flag=1;
			} 

		} 

				zaehler++;
				cout &lt;&lt; zaehler &lt;&lt; &quot;) &quot;; print();
				cout &lt;&lt; endl;

	}
}

void Bubblesort::swap(int j){

	int tmp = A[j];
    A[j] = A[j +1];
    A[j + 1] = tmp;
}

void Bubblesort::print() {

	//cout &lt;&lt; endl;
	for (int i=0; i&lt;size; i++) {
	cout &lt;&lt; A[i] &lt;&lt; &quot; &quot;;	
	}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/322001/blubblesort-ausgabe</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Jul 2026 13:52:54 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/322001.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 02 Dec 2013 20:44:24 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Blubblesort Ausgabe on Mon, 02 Dec 2013 20:44:24 GMT]]></title><description><![CDATA[<p>Hi Leute,</p>
<p>bin noch blutiger Anfänger in C++ und grade am Lernen. Meine aktuelle Aufgabe ist es, einen einfachen Sortieralgo Anhand von Bubblesort zu machen. Dabei ist alles in einer Klasse gekapselt.</p>
<p>Mittlerweile funktioniert das schon ziemlich gut. Das einzige Problem welches ich habe, dass ich die Zwischenschritte ausgeben muss. Dabei hab ich mir einfach einen integer als flag definiert und diesen einfach auf 0 ändere wenn nichts passiert ist. Ich soll nun 9 3 5 6 1 7 2 0 8 4 sortieren. Meine Ausgabe lautet:</p>
<blockquote>
<p>9 3 5 6 1 7 2 0 8 4<br />
Sortiere ...</p>
<ol>
<li>3 5 6 1 7 2 0 8 4 9</li>
<li>3 5 1 6 2 0 7 4 8 9</li>
<li>3 1 5 2 0 6 4 7 8 9</li>
<li>1 3 2 0 5 4 6 7 8 9</li>
<li>1 2 0 3 4 5 6 7 8 9</li>
<li>1 0 2 3 4 5 6 7 8 9</li>
<li>0 1 2 3 4 5 6 7 8 9</li>
<li>0 1 2 3 4 5 6 7 8 9<br />
Sortierte Liste:<br />
0 1 2 3 4 5 6 7 8 9</li>
</ol>
</blockquote>
<p>Funktioniert alles bestens, aber ich hab halt den letzten Schritt doppelt ausgegeben. Ist ja auch klar. Davor hatte sich noch etwas geändert also läuft er noch einmal durch, dann ist keine änderung mehr vorhanden und es wird abgebrochen. In der Aufgabenstellung wird nun aber die Zeile <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f60e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--smiling_face_with_sunglasses"
      title="8)"
      alt="😎"
    /> nicht mehr ausgeben. Hat jemand eine Idee, wie ich das implementieren kann?</p>
<p>Vielen Dank!!!</p>
<pre><code>#include&lt;iostream&gt;
#include&quot;Bubblesort.h&quot;
using namespace std;

void Bubblesort::sort( int *array, int size )
{
  int flag=1; int zaehler=0;

  print();
  cout &lt;&lt; endl;
  cout &lt;&lt; &quot;Sortiere ...&quot; &lt;&lt; endl;
  cout &lt;&lt; endl;

    for(int i = 0; i &lt; size -1 &amp;&amp; flag; ++i)
    {
		flag=0;
		for (int j=0; j &lt; size -i -1; j++) 
		{
			// check ob kleiner als vorgänger
			if (A[j] &gt; A[j + 1])
			{	  
				// Werte vertauschen
				swap(j);		
				// es wurde etwas verändert
				flag=1;
			} 

		} 

				zaehler++;
				cout &lt;&lt; zaehler &lt;&lt; &quot;) &quot;; print();
				cout &lt;&lt; endl;

	}
}

void Bubblesort::swap(int j){

	int tmp = A[j];
    A[j] = A[j +1];
    A[j + 1] = tmp;
}

void Bubblesort::print() {

	//cout &lt;&lt; endl;
	for (int i=0; i&lt;size; i++) {
	cout &lt;&lt; A[i] &lt;&lt; &quot; &quot;;	
	}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2369449</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369449</guid><dc:creator><![CDATA[warrie87]]></dc:creator><pubDate>Mon, 02 Dec 2013 20:44:24 GMT</pubDate></item><item><title><![CDATA[Reply to Blubblesort Ausgabe on Mon, 02 Dec 2013 21:23:34 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">if (flag) print();
</code></pre>
<p>??</p>
<p>wahrscheinlich zu einfach, da wärst du ja selber drauf gekommen, wenn du einen Bubble Sort hinkriegst...</p>
<p>Ein besserer Typ für flag wäre übrigens bool.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369462</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369462</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Mon, 02 Dec 2013 21:23:34 GMT</pubDate></item><item><title><![CDATA[Reply to Blubblesort Ausgabe on Mon, 02 Dec 2013 21:40:44 GMT]]></title><description><![CDATA[<p>Natürlich! Das war es.</p>
<p>Nach x Stunden programmieren sieht man manchmal den Wald vor lauter Bäumen nicht mehr. Danke!!!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369463</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369463</guid><dc:creator><![CDATA[warrie87]]></dc:creator><pubDate>Mon, 02 Dec 2013 21:40:44 GMT</pubDate></item></channel></rss>