<?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[Sätze sortieren mittels Bubblesort]]></title><description><![CDATA[<p>Hey Leute,</p>
<p>ich habe folgendes Problem, ein Kumpel von mir soll mittels c++ und bubblesort einen Satz nach ASCII sortieren und dabei aber auch auf die Leerzeichen achten. Und da hapert es bei mir. Wie gebe ich den sortierten Satz wieder mit leerzeichen aus?</p>
<p>hier mal der code:</p>
<pre><code class="language-cpp">#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;conio.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;

using namespace std;

int main(int argc, char *argv[])
{
    char satz[99]=&quot;hallo wie gehtS&quot;;
    char temp;
    int a,b;

    cout&lt;&lt;satz;                    
    for(a=0; a&lt;=99; a++)
    {
       for(b=0; b&lt;=99; b++)
       {              
                  if(satz[b] &gt; satz[b+1])
                  {
                       temp = satz[b];
                       satz[b]= satz[b+1];
                       satz[b+1]=temp;                              
                  }
       } 

    }

     for(b=0; b&lt;=99; b++)
     {
      cout&lt;&lt;satz[b];         
     } 
         getch();
}
</code></pre>
<p>Ist wichtig er brauch das zu morgen. Wäre dankbar für eure Hilfe.</p>
<p>Gruß</p>
<p>iLLu444</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/181181/sätze-sortieren-mittels-bubblesort</link><generator>RSS for Node</generator><lastBuildDate>Tue, 22 Sep 2026 07:40:18 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/181181.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 10 May 2007 18:40:51 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Sätze sortieren mittels Bubblesort on Thu, 10 May 2007 18:40:51 GMT]]></title><description><![CDATA[<p>Hey Leute,</p>
<p>ich habe folgendes Problem, ein Kumpel von mir soll mittels c++ und bubblesort einen Satz nach ASCII sortieren und dabei aber auch auf die Leerzeichen achten. Und da hapert es bei mir. Wie gebe ich den sortierten Satz wieder mit leerzeichen aus?</p>
<p>hier mal der code:</p>
<pre><code class="language-cpp">#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;conio.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;

using namespace std;

int main(int argc, char *argv[])
{
    char satz[99]=&quot;hallo wie gehtS&quot;;
    char temp;
    int a,b;

    cout&lt;&lt;satz;                    
    for(a=0; a&lt;=99; a++)
    {
       for(b=0; b&lt;=99; b++)
       {              
                  if(satz[b] &gt; satz[b+1])
                  {
                       temp = satz[b];
                       satz[b]= satz[b+1];
                       satz[b+1]=temp;                              
                  }
       } 

    }

     for(b=0; b&lt;=99; b++)
     {
      cout&lt;&lt;satz[b];         
     } 
         getch();
}
</code></pre>
<p>Ist wichtig er brauch das zu morgen. Wäre dankbar für eure Hilfe.</p>
<p>Gruß</p>
<p>iLLu444</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1282600</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1282600</guid><dc:creator><![CDATA[illu444]]></dc:creator><pubDate>Thu, 10 May 2007 18:40:51 GMT</pubDate></item><item><title><![CDATA[Reply to Sätze sortieren mittels Bubblesort on Thu, 10 May 2007 19:30:52 GMT]]></title><description><![CDATA[<p>Nachdenken ...</p>
<p>Du machst ne for Schleife for(a=0; a&lt;=99; a++), aber der String hat nur 16 Zeichen. Da kann doch nur Mist passieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1282633</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1282633</guid><dc:creator><![CDATA[feigling]]></dc:creator><pubDate>Thu, 10 May 2007 19:30:52 GMT</pubDate></item><item><title><![CDATA[Reply to Sätze sortieren mittels Bubblesort on Thu, 10 May 2007 19:49:36 GMT]]></title><description><![CDATA[<p>Ja gut, eigentlich sollte ein satz mittels cin eingegeben werden der max. 99 Zeichen lang sein.</p>
<p>Wie läuft das dort?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1282643</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1282643</guid><dc:creator><![CDATA[illu444]]></dc:creator><pubDate>Thu, 10 May 2007 19:49:36 GMT</pubDate></item><item><title><![CDATA[Reply to Sätze sortieren mittels Bubblesort on Thu, 10 May 2007 19:52:38 GMT]]></title><description><![CDATA[<p>Dieser Thread wurde von Moderator/in <a href="http://www.c-plusplus.net/forum/profile-var-mode-is-viewprofile-and-u-is-14811.html" rel="nofollow">Tim</a> aus dem Forum <a href="http://www.c-plusplus.net/forum/viewforum-var-f-is-10.html" rel="nofollow">ANSI C</a> in das Forum <a href="http://www.c-plusplus.net/forum/viewforum-var-f-is-15.html" rel="nofollow">C++</a> verschoben.</p>
<p>Im Zweifelsfall bitte auch folgende Hinweise beachten:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39405.html" rel="nofollow">C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?</a></p>
<p><em>Dieses Posting wurde automatisch erzeugt.</em></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1282644</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1282644</guid><dc:creator><![CDATA[C++ Forumbot]]></dc:creator><pubDate>Thu, 10 May 2007 19:52:38 GMT</pubDate></item><item><title><![CDATA[Reply to Sätze sortieren mittels Bubblesort on Thu, 10 May 2007 20:06:47 GMT]]></title><description><![CDATA[<p>Bist du sicher dass die <em>Zeichen</em> sortiert werden sollen, nicht die Wörter?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1282658</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1282658</guid><dc:creator><![CDATA[finix]]></dc:creator><pubDate>Thu, 10 May 2007 20:06:47 GMT</pubDate></item><item><title><![CDATA[Reply to Sätze sortieren mittels Bubblesort on Thu, 10 May 2007 20:25:08 GMT]]></title><description><![CDATA[<p>Japp die Zeichen sollen sortiert werden also jeder einzelne Buchstabe nach ASCII-Code.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1282668</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1282668</guid><dc:creator><![CDATA[illu444]]></dc:creator><pubDate>Thu, 10 May 2007 20:25:08 GMT</pubDate></item><item><title><![CDATA[Reply to Sätze sortieren mittels Bubblesort on Thu, 10 May 2007 21:20:07 GMT]]></title><description><![CDATA[<p>illu444 schrieb:</p>
<blockquote>
<p>Ja gut, eigentlich sollte ein satz mittels cin eingegeben werden der max. 99 Zeichen lang sein.</p>
<p>Wie läuft das dort?</p>
</blockquote>
<p>char Titel[100];<br />
cin.getline(Titel, 100, '\n');</p>
<p>ausgabe:</p>
<p>cout &lt;&lt; Titel;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1282686</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1282686</guid><dc:creator><![CDATA[Stelfer]]></dc:creator><pubDate>Thu, 10 May 2007 21:20:07 GMT</pubDate></item><item><title><![CDATA[Reply to Sätze sortieren mittels Bubblesort on Thu, 10 May 2007 21:27:19 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;conio.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;

using namespace std;

int main(int argc, char *argv[])
{
    char satz[98];
    char temp;
    int a=0,b=0;
    cout&lt;&lt;&quot;Geben Sie einen Satz ein: &quot;;
    cin.getline(satz, 100, '\n');  

    for(a=0; a&lt;=99; a++)
    {
       for(b=0; b&lt;=99; b++)
       {    

                  if(satz[b] &gt; satz[b+1])
                  {
                       if (satz[b]==' ')
                       {
                       temp = satz[b];
                       satz[b]= satz[b+1];
                       satz[b+1]=temp;               
                       /*}  
                       temp = satz[b];
                       satz[b]= satz[b+1];
                       satz[b+1]=temp;  */     

       }       
}
}
}
for(int b=0;b&lt;=99;b++)
cout&lt;&lt;satz[b];        

getch();
}
</code></pre>
<p>so sieht mein prog im mom aus, aber funktionieren tuts net.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1282688</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1282688</guid><dc:creator><![CDATA[illu444]]></dc:creator><pubDate>Thu, 10 May 2007 21:27:19 GMT</pubDate></item><item><title><![CDATA[Reply to Sätze sortieren mittels Bubblesort on Fri, 11 May 2007 03:32:10 GMT]]></title><description><![CDATA[<p>char satz[98];<br />
-&gt; Satz ist 98 Zeichen lang (ergo gehyen die Indexe von 0 bis 97)</p>
<p>for(b=0; b&lt;=99; b++)<br />
-&gt; b wird am Ende 98, resp. 99</p>
<p>satz[b]<br />
-&gt; Zugriff auf das 99. Element, wo es nur 98 gibt<br />
-&gt; BUMM<br />
(btw nimmt getline vorher noch 100 Zeichern, da sollte es auch schon krachen)</p>
<p>if (satz[b]==' ')<br />
Warum? Jetzt machst du nur was, wenn du an nem Leerzeichen angekommen bist.<br />
Was genau meinst du mit auf Leerzeichen achten? Sollen die ignoriert werden? Wenn ja, dann nimm sie doch vorher raus und mach dann deinen bubble sort.</p>
<p>Wenn schon bekannt: nutze std::string statt char array.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1282737</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1282737</guid><dc:creator><![CDATA[Shinja]]></dc:creator><pubDate>Fri, 11 May 2007 03:32:10 GMT</pubDate></item><item><title><![CDATA[Reply to Sätze sortieren mittels Bubblesort on Sun, 13 May 2007 18:12:19 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/13317">@Shinja</a>: String statt char Feld ist keine Lösung seines Problems. Kann ja sein das dies eine Vorgabe ist, die eingehalten werden soll. Also ich versuch immer nur mit den mitteln zu arbeiten, die der Threadersteller mir gibt.</p>
<p>Ich hab mich mal rangesetzte, nur das mit den vielen chars im Main gefällt mir noch nicht so.</p>
<pre><code class="language-cpp">#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;conio.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;

using namespace std;

char *eingabe() {
     char satz[100] = &quot;&quot;;
     cout&lt;&lt;&quot;Bitte geben sie einen Satz ein (alles klein schreiben): &quot;&lt;&lt;endl;
     cin.getline(satz, 100, '\n');
     return satz;
}

bool gueltigesSortierZeichen(char buchstabe1, char buchstabe2) 
{
     // Wenn der 1. Buchstabe ein Leerzeichen oder Zeilenumbruchzeichen ist
     // wird false zurückgegeben
     if(buchstabe1 == ' ' || buchstabe1 == '\n') {
          return false;
     }
     // Wenn der 2. Buchstabe ein Leerzeichen oder Zeilenumbruchzeichen ist
     // wird false zurückgegeben
     if(buchstabe2 == ' ' || buchstabe2 == '\n') {
          return  false;
     }
     // Wenn der 2. Buchstabe keine Zeichen ist
     if((int) buchstabe2 == 0) {
          return  false;
     }

     return true;
}

char *sortieren(char satz[100]) {
     bool marke;
     char temp;

     do
     {
        marke=0;
        for(int a=0;a&lt;=100 &amp;&amp; satz[a] != '\n' &amp;&amp; (int) satz[a] != 0;a++)
        {
           if(satz[a] &gt; satz[a+1] &amp;&amp; gueltigesSortierZeichen(satz[a], satz[a+1]))
           {
             temp = satz[a];
             satz[a] = satz[a+1];
             satz[a+1]=temp;
             marke=1; 
           }                  
        }
    }
    while(marke == 1);
    return satz;
}

void ausgabe(char ausgabe[100]) {
     cout&lt;&lt;endl&lt;&lt;&quot;Nach Buchstaben sortiert wuerde folgendes rauskommen: &quot;&lt;&lt;endl&lt;&lt;ausgabe&lt;&lt;endl;
}

int main(int argc, char *argv[])
{
    char satz[100] = &quot;&quot;;

    char *eingabewert = eingabe();
    for(int i =0; i &lt; 99;i++) { satz[i] = eingabewert[i]; } 

    char *sortierwert = sortieren(satz);
    for(int i =0; i &lt; 99;i++) { satz[i] = sortierwert[i]; } 

    ausgabe(satz);

    getch();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1284197</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1284197</guid><dc:creator><![CDATA[Neiko]]></dc:creator><pubDate>Sun, 13 May 2007 18:12:19 GMT</pubDate></item><item><title><![CDATA[Reply to Sätze sortieren mittels Bubblesort on Sun, 13 May 2007 23:51:28 GMT]]></title><description><![CDATA[<p>Hi,<br />
mir ist immer noch nicht kar, wie denn eigentlich sortiert werden soll</p>
<p>Gegeben:<br />
&quot;hallo wie gehtS&quot;<br />
so sortiert:<br />
&quot;Saeeg hhi llotw&quot;<br />
oder so sortiert:<br />
&quot;_<em>Saeeghhillotw&quot;<br />
(</em> steht für blank)</p>
<p>Wenn entsprechend &quot;__Saeeghhillotw&quot; sortiert werden soll, dann könnte der folgende Code zur Lösung des Problems beitragen:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
void bubble ( string&amp; s )
{ char c;
  for (int i = 0; i &lt; s.length(); i++)
    for ( int j = i; j &lt; s.length(); j++)
       if (s[j] &lt; s[i]) { c = s[i]; s[i] = s[j]; s[j] = c; }
}
. . .
string satz = &quot;hallo wie gehtS&quot;;
bubble ( satz );
cout &lt;&lt; satz &lt;&lt; endl;  // out: __Saeeghhillotw
. . .
</code></pre>
<p>viele Grüsse tesu<br />
(auf Nachtwache:)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1284348</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1284348</guid><dc:creator><![CDATA[tesuji]]></dc:creator><pubDate>Sun, 13 May 2007 23:51:28 GMT</pubDate></item></channel></rss>