<?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[Permutation]]></title><description><![CDATA[<p>Guten Tag,</p>
<p>ich habe hiermal eine doch recht einfache und nicht gute laufzeit fähige Version eines Permutationsalgorithmus für ein 7 buchstabiges Wort.<br />
Gibt es hier jemand der die nextPermutation() in der &lt;algorithm&gt; verständlich machen kann oder en Beispiel für einen n-buchstabigen Algorithmus hat ?</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;cstdlib&gt;

using namespace std;

int main()
{
int n = 7, Iw1, Iw2, Iw3, Iw4, Iw5, Iw6, Iw7, z = 1, h;

char lw[6], ausgabew[6];
ofstream perm(&quot;perm.txt&quot;, ios::out);

/*
cout &lt;&lt; &quot;Geben sie ein 7 Buchstabiges Wort ein !\n\n&quot;;

for (int i=0; i&lt;n; i++)
{
	cin &gt;&gt; lw[i];
}
*/

lw[0] = 's';
lw[1] = 't';
lw[2] = 'e';
lw[3] = 'p';
lw[4] = 'h';
lw[5] = 'a';
lw[6] = 'n';

	for (Iw1 = 0; Iw1 &lt; n; Iw1++)
	{
		for (Iw2 = 0; Iw2 &lt; n; Iw2++)
		{
			for (Iw3 = 0; Iw3 &lt; n; Iw3++)
			{
				for (Iw4 = 0; Iw4 &lt; n; Iw4++)
				{
					for (Iw5 = 0; Iw5 &lt; n; Iw5++)
					{
						for (Iw6 = 0; Iw6 &lt; n; Iw6++)
						{
							if (Iw6 != Iw5 &amp;&amp; Iw6 != Iw4 &amp;&amp; Iw6 != Iw3 &amp;&amp; Iw6 != Iw2 &amp;&amp; Iw6 != Iw1 &amp;&amp; Iw5 != Iw4 &amp;&amp; Iw5 != Iw3 &amp;&amp; Iw5 != Iw2 &amp;&amp; Iw5 != Iw1 &amp;&amp; Iw4 != Iw1 &amp;&amp; Iw4 != Iw2 &amp;&amp; Iw4 != Iw3 &amp;&amp; Iw3 != Iw1 &amp;&amp; Iw3 != Iw2 &amp;&amp; Iw2 != Iw1)
							{
								Iw7 = 28 - (Iw1 + Iw2 + Iw3 + Iw4 + Iw5 + Iw6) - 7;

								// Excel:
                                // ausgabew = lw(Iw1) &amp; lw(Iw2) &amp; lw(Iw3) &amp; lw(Iw4) &amp; lw(Iw5) &amp; lw(Iw6) &amp; lw(Iw7)

								ausgabew[0] = lw[Iw1];
								ausgabew[1] = lw[Iw2];
								ausgabew[2] = lw[Iw3];
								ausgabew[3] = lw[Iw4];
								ausgabew[4] = lw[Iw5];
								ausgabew[5] = lw[Iw6];
								ausgabew[6] = lw[Iw7];

								for (int j=0; j&lt;7; j++)
								{
									cout &lt;&lt; ausgabew[j];
									perm &lt;&lt; ausgabew[j];
								}

								cout &lt;&lt; &quot;\n&quot;;
								perm &lt;&lt; &quot;\n&quot;;

							}
						}
					}
				}
			}
		}
	}

	perm.close();

return 0;
}
</code></pre>
<p>Danke für gute Ansätze <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>
]]></description><link>https://www.c-plusplus.net/forum/topic/111447/permutation</link><generator>RSS for Node</generator><lastBuildDate>Mon, 17 Aug 2026 19:06:11 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/111447.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 01 Jun 2005 08:15:58 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Permutation on Wed, 01 Jun 2005 08:15:58 GMT]]></title><description><![CDATA[<p>Guten Tag,</p>
<p>ich habe hiermal eine doch recht einfache und nicht gute laufzeit fähige Version eines Permutationsalgorithmus für ein 7 buchstabiges Wort.<br />
Gibt es hier jemand der die nextPermutation() in der &lt;algorithm&gt; verständlich machen kann oder en Beispiel für einen n-buchstabigen Algorithmus hat ?</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;cstdlib&gt;

using namespace std;

int main()
{
int n = 7, Iw1, Iw2, Iw3, Iw4, Iw5, Iw6, Iw7, z = 1, h;

char lw[6], ausgabew[6];
ofstream perm(&quot;perm.txt&quot;, ios::out);

/*
cout &lt;&lt; &quot;Geben sie ein 7 Buchstabiges Wort ein !\n\n&quot;;

for (int i=0; i&lt;n; i++)
{
	cin &gt;&gt; lw[i];
}
*/

lw[0] = 's';
lw[1] = 't';
lw[2] = 'e';
lw[3] = 'p';
lw[4] = 'h';
lw[5] = 'a';
lw[6] = 'n';

	for (Iw1 = 0; Iw1 &lt; n; Iw1++)
	{
		for (Iw2 = 0; Iw2 &lt; n; Iw2++)
		{
			for (Iw3 = 0; Iw3 &lt; n; Iw3++)
			{
				for (Iw4 = 0; Iw4 &lt; n; Iw4++)
				{
					for (Iw5 = 0; Iw5 &lt; n; Iw5++)
					{
						for (Iw6 = 0; Iw6 &lt; n; Iw6++)
						{
							if (Iw6 != Iw5 &amp;&amp; Iw6 != Iw4 &amp;&amp; Iw6 != Iw3 &amp;&amp; Iw6 != Iw2 &amp;&amp; Iw6 != Iw1 &amp;&amp; Iw5 != Iw4 &amp;&amp; Iw5 != Iw3 &amp;&amp; Iw5 != Iw2 &amp;&amp; Iw5 != Iw1 &amp;&amp; Iw4 != Iw1 &amp;&amp; Iw4 != Iw2 &amp;&amp; Iw4 != Iw3 &amp;&amp; Iw3 != Iw1 &amp;&amp; Iw3 != Iw2 &amp;&amp; Iw2 != Iw1)
							{
								Iw7 = 28 - (Iw1 + Iw2 + Iw3 + Iw4 + Iw5 + Iw6) - 7;

								// Excel:
                                // ausgabew = lw(Iw1) &amp; lw(Iw2) &amp; lw(Iw3) &amp; lw(Iw4) &amp; lw(Iw5) &amp; lw(Iw6) &amp; lw(Iw7)

								ausgabew[0] = lw[Iw1];
								ausgabew[1] = lw[Iw2];
								ausgabew[2] = lw[Iw3];
								ausgabew[3] = lw[Iw4];
								ausgabew[4] = lw[Iw5];
								ausgabew[5] = lw[Iw6];
								ausgabew[6] = lw[Iw7];

								for (int j=0; j&lt;7; j++)
								{
									cout &lt;&lt; ausgabew[j];
									perm &lt;&lt; ausgabew[j];
								}

								cout &lt;&lt; &quot;\n&quot;;
								perm &lt;&lt; &quot;\n&quot;;

							}
						}
					}
				}
			}
		}
	}

	perm.close();

return 0;
}
</code></pre>
<p>Danke für gute Ansätze <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>
]]></description><link>https://www.c-plusplus.net/forum/post/800191</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/800191</guid><dc:creator><![CDATA[Lord Calf]]></dc:creator><pubDate>Wed, 01 Jun 2005 08:15:58 GMT</pubDate></item><item><title><![CDATA[Reply to Permutation on Wed, 01 Jun 2005 09:09:23 GMT]]></title><description><![CDATA[<p>next_permutation() arbeitet über lexikografische ordnung der elemente - um damit alle permutationen zu erwischen, muss zunächst sortiert werden. der vorteil ist, dass das ganze auch bei vorhandensein doppelter elemente funktioniert.<br />
eine einfache rekursive funktion, die keine rücksicht auf doppelte elemente nimmt und keine lexikografische ordnung erfordert (sie allerdings erhält, wenn die menge sortiert war), könnte so aus sehen:</p>
<pre><code class="language-cpp">char s[] = &quot;abcdefghi&quot;;
void do_something(); // wird für jede einzelne permutation aufgerufen
void iterate_perm(char* where, int level)
{
    if ( level &gt; 1 )
    {
        for ( int i = 0; i &lt; level; ++i )
        {
            iterate_perm( where + 1, i - 1 );
            std::swap( where[ 0 ], where[ 1 ] );
        }
    }
    else
    {
        do_something();
    }
}
int main()
{
    iterate_perm( s, sizeof( s ) - 1 );
}
</code></pre>
<p>man kann hier noch einiges verbessern, das ist nur zur verdeutlichung des konzepts.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/800243</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/800243</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Wed, 01 Jun 2005 09:09:23 GMT</pubDate></item><item><title><![CDATA[Reply to Permutation on Wed, 01 Jun 2005 10:52:37 GMT]]></title><description><![CDATA[<p>Was ist das Problem das der hier in der CMD nix ausgibt ??</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;ctime&gt;
using namespace std;

char s[] = &quot;abcdefghi&quot;; 

void sleep()
{
	int c=50 ,d=0;

	while (d!=c)
	{
		int start=time(0);

		while(start==time(0))
		{
			// tue nichts
		}

		d+=5;
	}
}

// void do_something(); // wird für jede einzelne permutation aufgerufen 

void iterate_perm (char* where, int level) 
{ 
    if (level &gt; 1) 
    { 
        for (int i = 0; i &lt; level; i++) 
        { 
            iterate_perm (where + 1, i - 1); 
            std::swap (where [0], where [1]); 
        } 
    } 
    else 
    { 
        sleep();
    } 
} 

int main() 
{ 
    iterate_perm (s, sizeof(s) - 1);

	for (int i=0; i&lt;sizeof(s)-1; i++)
	{
		cout &lt;&lt; s[i];
	}

	return 0;
}
</code></pre>
<p>Greez Sven aus Dresden <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/800311</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/800311</guid><dc:creator><![CDATA[Lord Calf]]></dc:creator><pubDate>Wed, 01 Jun 2005 10:52:37 GMT</pubDate></item><item><title><![CDATA[Reply to Permutation on Wed, 01 Jun 2005 12:41:23 GMT]]></title><description><![CDATA[<p>das liegt daran, dass die funktion mist ist :p</p>
<pre><code class="language-cpp">void iterate_perm (char* where, int level)
{
    if (level &gt; 1)
    {
        for (int i = 0; i &lt; level; i++)
        {
            std::swap (where [0], where [i]);
            iterate_perm (where + 1, level - 1);
            std::swap (where [0], where [i]);
        }
    }
    else
    {
        std::cout &lt;&lt; s &lt;&lt; std::endl;
    }
}
</code></pre>
<p>so müsste es funktionieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/800423</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/800423</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Wed, 01 Jun 2005 12:41:23 GMT</pubDate></item></channel></rss>