<?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[std::next_permutation]]></title><description><![CDATA[<p>Hey,</p>
<p>ich habe z.B. ein set:</p>
<pre><code>std::set&lt;char&gt; dictionary = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
								  'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F',
								  'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
								  'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };
</code></pre>
<p>Hiervon möchte ich alle Möglichen 5stelligen Kombinationen generieren lassen.<br />
Bin auf std::next_permutation gestoßen, nur wie beschränke ich das auf eine Länge von 5?</p>
<p>Grüße</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/328788/std-next_permutation</link><generator>RSS for Node</generator><lastBuildDate>Tue, 07 Jul 2026 06:44:48 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/328788.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 27 Oct 2014 10:18:26 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to std::next_permutation on Mon, 27 Oct 2014 10:18:26 GMT]]></title><description><![CDATA[<p>Hey,</p>
<p>ich habe z.B. ein set:</p>
<pre><code>std::set&lt;char&gt; dictionary = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
								  'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F',
								  'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
								  'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };
</code></pre>
<p>Hiervon möchte ich alle Möglichen 5stelligen Kombinationen generieren lassen.<br />
Bin auf std::next_permutation gestoßen, nur wie beschränke ich das auf eine Länge von 5?</p>
<p>Grüße</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2424279</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2424279</guid><dc:creator><![CDATA[permutation...]]></dc:creator><pubDate>Mon, 27 Oct 2014 10:18:26 GMT</pubDate></item><item><title><![CDATA[Reply to std::next_permutation on Mon, 27 Oct 2014 11:14:46 GMT]]></title><description><![CDATA[<blockquote>
<p>Hiervon möchte ich alle Möglichen 5stelligen Kombinationen generieren lassen.</p>
</blockquote>
<p>Ich glaub' nicht dass du genug Speicher dafür hast.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2424286</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2424286</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Mon, 27 Oct 2014 11:14:46 GMT</pubDate></item><item><title><![CDATA[Reply to std::next_permutation on Mon, 27 Oct 2014 11:19:40 GMT]]></title><description><![CDATA[<p>Das sind schon ohne Wiederholung etwa 777 Mio. Möglichkeiten. <code>std::next_permutation</code> ist hierbei nicht sonderlich gut geeignet (was nicht bedeutet, dass sich nicht ein umständliches Beispiel konstruieren lässt, das <code>std::next_permutation</code> nutzt).</p>
<p>Aber bitte:</p>
<pre><code>#include &lt;set&gt;
#include &lt;array&gt;
#include &lt;algorithm&gt;
#include &lt;iterator&gt;
#include &lt;iostream&gt;

int main()
{
	// typedef std::set&lt;char&gt; DictType; // std::set-Iteratoren sind AFAIK langsam
	typedef std::array&lt;char, 26 * 2 + 10&gt; DictType;
	const DictType dictionary = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
								 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F',
								 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
								 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
	enum
	{
		CombinationLen = 5
	};

	std::array&lt;DictType::const_iterator, CombinationLen&gt; Stack;
	Stack.fill(std::begin(dictionary));

	typedef std::array&lt;DictType::value_type, CombinationLen&gt; CombinationType;
	std::vector&lt;CombinationType&gt; Combinations;

	for(std::size_t Depth = 0; ;)
	{
		if(Stack[Depth] == std::end(dictionary))
		{
			Stack[Depth] = std::begin(dictionary);
			if(Depth == 0)
			{
				break;
			}
			else
			{
				--Depth;
				++Stack[Depth];
			}
		}
		else
		{
			auto CurrentPos = std::next(std::begin(Stack), Depth);
			if(std::find(std::begin(Stack), CurrentPos, Stack[Depth]) != CurrentPos)
			{
				++Stack[Depth];
			}
			else
			{
				if(Depth + 1 != CombinationLen)
				{
					++Depth;
				}
				else
				{
					CombinationType NewComb;
					for(std::size_t i = 0; i &lt; CombinationLen; ++i)
					{
						NewComb[i] = *Stack[i];
					}
					Combinations.push_back(NewComb);
					++Stack[Depth];
				}
			}
		}
	}

	for(auto const&amp; Entry : Combinations)
	{
		for(auto Char : Entry)
		{
			std::cout &lt;&lt; Char &lt;&lt; ' ';
		}
		std::cout &lt;&lt; '\n';
	}
}
</code></pre>
<p>Edit: Mein Code gibt auch Kombinationen ohne Wiederholungen aus, ansonsten wäre es trivial.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2424287</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2424287</guid><dc:creator><![CDATA[Fytch]]></dc:creator><pubDate>Mon, 27 Oct 2014 11:19:40 GMT</pubDate></item><item><title><![CDATA[Reply to std::next_permutation on Mon, 27 Oct 2014 11:18:41 GMT]]></title><description><![CDATA[<p>Moechtest Du alle geordneten Kombinationen haben, d.h. {a, b, c, d, e} != {e, d, c, b, a} oder spielt die Ordnung keine Rolle?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2424289</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2424289</guid><dc:creator><![CDATA[asdfasddf]]></dc:creator><pubDate>Mon, 27 Oct 2014 11:18:41 GMT</pubDate></item><item><title><![CDATA[Reply to std::next_permutation on Mon, 27 Oct 2014 14:45:10 GMT]]></title><description><![CDATA[<p>Ohne Beachtung der Reihenfolge könnte es so aussehen:</p>
<pre><code>#include &lt;iostream&gt;

int main()
{
	char const chars[] = &quot;abcdefghijklmnopqrstuvwxyz&quot;
	                     &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;
	                     &quot;0123456789&quot;;

	for (std::size_t a = 4; a != sizeof chars - 1; ++a)
	for (std::size_t b = 3; b != a; ++b)
	for (std::size_t c = 2; c != b; ++c)
	for (std::size_t d = 1; d != c; ++d)
	for (std::size_t e = 0; e != d; ++e)
		std::cout &lt;&lt; chars[e] &lt;&lt; chars[d] &lt;&lt; chars[c] &lt;&lt; chars[b] &lt;&lt; chars[a] &lt;&lt; '\n';
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2424325</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2424325</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Mon, 27 Oct 2014 14:45:10 GMT</pubDate></item></channel></rss>