<?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[Rekurstion &#x2F; Permutation auf STring]]></title><description><![CDATA[<p>Hallo Leute,</p>
<p>zu anfang, ich hab die Sache mit der Rekurstion in C schon nicht hundert Pro verstanden, es aber dann irgendwie bekommen.</p>
<p>Jetzt versuche ich seit Stunden das ganze mal in C++ mit nem String umzusetzten. Ich gebe gleich völlig entnervt auf.</p>
<p>Das ist alles was ich noch an Code habe (hab schon x - mal gelöscht und geändert).</p>
<pre><code>int comb(std::string source, size_t deep){

for (auto it = source.begin(); it != source.end(); it++){

	std::cout &lt;&lt; *it;   

	if (deep &lt; source.size()){     

	    comb(source, deep+1);       
	}

}

}
</code></pre>
<p>main.cpp :</p>
<pre><code>std::string test = &quot;ab&quot;;
comb(test, 0);
</code></pre>
<p>Ich kriegs echt nicht auf die Reihe. Kann mir mal jmd. unter die Arme greifen?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/328543/rekurstion-permutation-auf-string</link><generator>RSS for Node</generator><lastBuildDate>Tue, 07 Jul 2026 12:21:00 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/328543.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 15 Oct 2014 11:50:10 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Rekurstion &#x2F; Permutation auf STring on Wed, 15 Oct 2014 11:50:10 GMT]]></title><description><![CDATA[<p>Hallo Leute,</p>
<p>zu anfang, ich hab die Sache mit der Rekurstion in C schon nicht hundert Pro verstanden, es aber dann irgendwie bekommen.</p>
<p>Jetzt versuche ich seit Stunden das ganze mal in C++ mit nem String umzusetzten. Ich gebe gleich völlig entnervt auf.</p>
<p>Das ist alles was ich noch an Code habe (hab schon x - mal gelöscht und geändert).</p>
<pre><code>int comb(std::string source, size_t deep){

for (auto it = source.begin(); it != source.end(); it++){

	std::cout &lt;&lt; *it;   

	if (deep &lt; source.size()){     

	    comb(source, deep+1);       
	}

}

}
</code></pre>
<p>main.cpp :</p>
<pre><code>std::string test = &quot;ab&quot;;
comb(test, 0);
</code></pre>
<p>Ich kriegs echt nicht auf die Reihe. Kann mir mal jmd. unter die Arme greifen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2422325</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2422325</guid><dc:creator><![CDATA[cpp_beginner_offl]]></dc:creator><pubDate>Wed, 15 Oct 2014 11:50:10 GMT</pubDate></item><item><title><![CDATA[Reply to Rekurstion &#x2F; Permutation auf STring on Wed, 15 Oct 2014 11:54:32 GMT]]></title><description><![CDATA[<p>Was soll die Funktion machen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2422327</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2422327</guid><dc:creator><![CDATA[Kellerautomat]]></dc:creator><pubDate>Wed, 15 Oct 2014 11:54:32 GMT</pubDate></item><item><title><![CDATA[Reply to Rekurstion &#x2F; Permutation auf STring on Wed, 15 Oct 2014 11:54:59 GMT]]></title><description><![CDATA[<p>Ps.: ich möchte alle möglichen kombinationen ausgeben, mit wiederholung.</p>
<p>aa<br />
ab<br />
bb<br />
ba</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2422328</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2422328</guid><dc:creator><![CDATA[cpp_beginner_off]]></dc:creator><pubDate>Wed, 15 Oct 2014 11:54:59 GMT</pubDate></item><item><title><![CDATA[Reply to Rekurstion &#x2F; Permutation auf STring on Wed, 15 Oct 2014 12:03:48 GMT]]></title><description><![CDATA[<p>Mir ist immer noch nicht klar, was die Funktion genau tut. 'source' ist also dein Set and Zeichen? Was ist 'deep'? Die Laenge des Strings? Was gibt die Funktion zurueck?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2422332</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2422332</guid><dc:creator><![CDATA[Kellerautomat]]></dc:creator><pubDate>Wed, 15 Oct 2014 12:03:48 GMT</pubDate></item><item><title><![CDATA[Reply to Rekurstion &#x2F; Permutation auf STring on Wed, 15 Oct 2014 12:07:06 GMT]]></title><description><![CDATA[<p>Sorry, hab den Code reinkopiert, der ist mittlerweile total vermurkst.</p>
<p>Also ich wollte source übergeben quase &quot;abc&quot;, solange deep &lt; string_länge, die funktion rekursiv aufrufen und die Buchstaben erst mal nur ausgeben.<br />
Später evtl. speichern oder so.</p>
<p>Aber ich kriegs heut gar nicht auf die Reihe.</p>
<p>Dachte mit bisschen durch Source durchiterieren und bisschen cout &lt;&lt; *it würde das gleich klappten.</p>
<p>Wie macht man das richtig?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2422333</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2422333</guid><dc:creator><![CDATA[beg_offl]]></dc:creator><pubDate>Wed, 15 Oct 2014 12:07:06 GMT</pubDate></item><item><title><![CDATA[Reply to Rekurstion &#x2F; Permutation auf STring on Wed, 15 Oct 2014 12:14:28 GMT]]></title><description><![CDATA[<p>Also der Code soll am Ende das machen, was hald seine &quot;Iterierende&quot; Variante macht , um mir x - For Schleifen zu ersparen.</p>
<pre><code>std::string test = &quot;ab&quot;;

for (auto i = test.begin(); i != test.end(); i++){

   for (auto j = test.begin(); j != test.end(); j++){

   std::cout &lt;&lt; *i &lt;&lt; *j &lt;&lt; &quot;\n&quot;;
}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2422337</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2422337</guid><dc:creator><![CDATA[beg_offl]]></dc:creator><pubDate>Wed, 15 Oct 2014 12:14:28 GMT</pubDate></item><item><title><![CDATA[Reply to Rekurstion &#x2F; Permutation auf STring on Wed, 15 Oct 2014 12:17:25 GMT]]></title><description><![CDATA[<p>mach aus jedem schleifen-body eine funktion, denk nach welche parameter du brauchst und wie sich die aendern.</p>
<p>sinn? for ist mal viel schneller als rekursion.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2422340</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2422340</guid><dc:creator><![CDATA[Kellerautomat]]></dc:creator><pubDate>Wed, 15 Oct 2014 12:17:25 GMT</pubDate></item><item><title><![CDATA[Reply to Rekurstion &#x2F; Permutation auf STring on Wed, 15 Oct 2014 14:26:37 GMT]]></title><description><![CDATA[<p>Bevor Du losprogrammierst solltest Du Dir klar machen wie genau die Rekursion funktionieren soll. Wenn ich es richtig verstehe, dann willst Du alle Zeichenketten einer gewissen Länge ausgeben, die sich mit den Zeichen eines gegebenen Strings bilden lassen.</p>
<p>Schritt 1: Du brauchst ein Abbruchkriterium. Nämlich der einfachste Fall, wenn die Länge 0 ist, dann ist die Funktion sehr einfach.</p>
<p>Schritt 2: Überleg Dir, wie Du die Funktion für Länge x realisieren würdest unter der Annahme, dass Du schon eine Funktion hast, die es für Länge x-1 tut.<br />
Nämlich: Liste alle Strings der Länge x-1 und kombiniere sie mit allen möglichen Zeichen.</p>
<p>Bevor Dir das nicht komplett klar ist, lohnt es sich imo nicht dazu Code zu schreiben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2422379</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2422379</guid><dc:creator><![CDATA[Jester]]></dc:creator><pubDate>Wed, 15 Oct 2014 14:26:37 GMT</pubDate></item><item><title><![CDATA[Reply to Rekurstion &#x2F; Permutation auf STring on Wed, 15 Oct 2014 14:27:58 GMT]]></title><description><![CDATA[<p>Kellerautomat schrieb:</p>
<blockquote>
<p>sinn? for ist mal viel schneller als rekursion.</p>
</blockquote>
<p>Und wenn die Länge der Strings nicht zwei sondern drei ist? Fünf? Siebzehn?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2422381</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2422381</guid><dc:creator><![CDATA[Jester]]></dc:creator><pubDate>Wed, 15 Oct 2014 14:27:58 GMT</pubDate></item><item><title><![CDATA[Reply to Rekurstion &#x2F; Permutation auf STring on Wed, 15 Oct 2014 14:51:35 GMT]]></title><description><![CDATA[<p>Kann z.B. so aussehen:</p>
<pre><code class="language-cpp">void comb(std::string source, size_t depth, std::string prefix=&quot;&quot;){
    if ( depth == 0 )
        std::cout &lt;&lt; prefix &lt;&lt; '\n';
    else
        for (auto c : source)
            comb(source, depth-1, prefix+c);      
}
</code></pre>
<p>Die verbleibende for-Schleife kann man nat. auch noch eliminieren.<br />
Oder zur Übung auch einfach mal nicht-rekursiv schreiben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2422383</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2422383</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Wed, 15 Oct 2014 14:51:35 GMT</pubDate></item><item><title><![CDATA[Reply to Rekurstion &#x2F; Permutation auf STring on Wed, 15 Oct 2014 15:19:05 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/324">@Jester</a></p>
<p>Mein Ansatz war jetzt eher :</p>
<p>Ich gebe der Funktin einen String mit 3 Zeichen, der Position bzw. das Zeichen das ich gerade &quot;anzeige&quot; und die gesamte Länge :</p>
<p>v</p>
<pre><code>oid reku_sucks(std::string source, int deep, int pos){

	for (auto it = source.begin(); it != source.end() ; it++){

		if (pos &lt; deep){
			reku_sucks(source, deep, pos + 1);
		}

	}
</code></pre>
<p>Aber ich glaube der Code ist immer noch falsch, und ich habe keinen Plan wo ich die Ausgabe mit std::cout &lt;&lt; *it setzten soll.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2422390</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2422390</guid><dc:creator><![CDATA[beg__]]></dc:creator><pubDate>Wed, 15 Oct 2014 15:19:05 GMT</pubDate></item><item><title><![CDATA[Reply to Rekurstion &#x2F; Permutation auf STring on Wed, 15 Oct 2014 16:46:31 GMT]]></title><description><![CDATA[<p>Ich habs jetzt erst mal mit &quot;in String speichern&quot; gelöst, weil ich mit dem std::cout &lt;&lt; nicht weiterkomme.</p>
<pre><code>int reku_sucks(std::string source, std::string out,  int deep, int pos){

	static int ctr = 0;

	for (auto it = source.begin(); it != source.end(); it++){

		out[pos] = *it;

		if (pos+1 &lt; deep){

			reku_sucks(source, out, deep, pos + 1);
		}
		else{
			std::cout &lt;&lt; out &lt;&lt; &quot;\n&quot;;
			ctr++;
		}
	}

	return ctr;
</code></pre>
<p>Diese Variante geht jetzt... aber naja... könnte ich statt out[pos] irgendwie mit push_back arbeiten`?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2422399</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2422399</guid><dc:creator><![CDATA[beg_]]></dc:creator><pubDate>Wed, 15 Oct 2014 16:46:31 GMT</pubDate></item><item><title><![CDATA[Reply to Rekurstion &#x2F; Permutation auf STring on Wed, 15 Oct 2014 18:28:43 GMT]]></title><description><![CDATA[<p>beg_ schrieb:</p>
<blockquote>
<p>Diese Variante geht jetzt... aber naja... könnte ich statt out[pos] irgendwie mit push_back arbeiten`?</p>
</blockquote>
<p>Ja, natürlich. Das wäre sogar wesentlich besser, da du dann nicht einen String passender Länge übergeben müsstest. Sich auf korrekte Nutzereingaben zu verlassen, wenn es nicht nötig wäre, ist nie eine gute Idee. Daher: Mit leeren String starten (guck mal, wie camper das gemacht hat) und dann in jeder Stufe mit push_back anhängen.</p>
<p>Die Ausgabe machst du dann, wenn du deine gewünschte Tiefe erreicht hast.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2422412</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2422412</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Wed, 15 Oct 2014 18:28:43 GMT</pubDate></item><item><title><![CDATA[Reply to Rekurstion &#x2F; Permutation auf STring on Thu, 16 Oct 2014 14:58:49 GMT]]></title><description><![CDATA[<p>Hm, muss mir das noch genauer ansehen, aber in mein obriges Bspl. kann ich jetzt push_back nicht wriklich einbauen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2422507</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2422507</guid><dc:creator><![CDATA[beg__]]></dc:creator><pubDate>Thu, 16 Oct 2014 14:58:49 GMT</pubDate></item><item><title><![CDATA[Reply to Rekurstion &#x2F; Permutation auf STring on Thu, 16 Oct 2014 17:08:25 GMT]]></title><description><![CDATA[<blockquote>
<p>Daher: Mit leeren String starten (guck mal, wie camper das gemacht hat) und dann in jeder Stufe mit push_back anhängen.</p>
<p>Die Ausgabe machst du dann, wenn du deine gewünschte Tiefe erreicht hast.</p>
</blockquote>
<p>Ich kann das nicht auf meine Version übertragen. Bin zu doof dafür. reku_sucks suckt wirklich. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f621.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--pouting_face"
      title=":rage:"
      alt="😡"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f621.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--pouting_face"
      title=":rage:"
      alt="😡"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f621.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--pouting_face"
      title=":rage:"
      alt="😡"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f621.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--pouting_face"
      title=":rage:"
      alt="😡"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f621.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--pouting_face"
      title=":rage:"
      alt="😡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2422523</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2422523</guid><dc:creator><![CDATA[beg_offl]]></dc:creator><pubDate>Thu, 16 Oct 2014 17:08:25 GMT</pubDate></item><item><title><![CDATA[Reply to Rekurstion &#x2F; Permutation auf STring on Fri, 17 Oct 2014 06:54:36 GMT]]></title><description><![CDATA[<p>JA!!! Ich habs mit push_back endlich zusammenbekommen!</p>
<pre><code>int comb(std::string source, std::string out, int pos){

 static int ctr = 0;  	

	 for (auto it = source.begin(); it != source.end(); it++){

 		out.push_back(*it);

 		if(pos+1  == source.length()){
 			std::cout &lt;&lt; out &lt;&lt; &quot;\n&quot;;
 			ctr++;

 		}else{  			
 			comb(source, out, pos+1); 			
 		}

 		out.pop_back();
 	}

   return ctr;

}//END COMB
</code></pre>
<p>Mein Fazit : Wer Rekursiv programmiert ist komisch veranlagt und echt eklig!!!!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2422593</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2422593</guid><dc:creator><![CDATA[beginner_CHAKKKA!!1]]></dc:creator><pubDate>Fri, 17 Oct 2014 06:54:36 GMT</pubDate></item><item><title><![CDATA[Reply to Rekurstion &#x2F; Permutation auf STring on Fri, 17 Oct 2014 07:31:13 GMT]]></title><description><![CDATA[<p>Lern einfach mal eine funktionale Sprache (z.B. Haskell) und du wirst ganz schnell Rekursion verstehen (auch komplexere).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2422605</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2422605</guid><dc:creator><![CDATA[Th69]]></dc:creator><pubDate>Fri, 17 Oct 2014 07:31:13 GMT</pubDate></item><item><title><![CDATA[Reply to Rekurstion &#x2F; Permutation auf STring on Fri, 17 Oct 2014 11:59:32 GMT]]></title><description><![CDATA[<p>Danke für den Tipp, aber das hat leider leider keinen Platz mehr auf meiner ToDo Liste <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</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2422641</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2422641</guid><dc:creator><![CDATA[beg_offl]]></dc:creator><pubDate>Fri, 17 Oct 2014 11:59:32 GMT</pubDate></item></channel></rss>