<?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[sortiertes array of ints]]></title><description><![CDATA[<p>Ich habe ein int array[1000]; und will nach und nach ints einfügen, so dass das array sortiert bleibt. Dabei können auch Werte zweimal auftreten. Also im Prinzip wie eine multimap, oder?</p>
<p>Hat da jemand Code für?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/303139/sortiertes-array-of-ints</link><generator>RSS for Node</generator><lastBuildDate>Mon, 10 Aug 2026 22:04:35 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/303139.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 06 May 2012 10:30:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to sortiertes array of ints on Sun, 06 May 2012 10:30:08 GMT]]></title><description><![CDATA[<p>Ich habe ein int array[1000]; und will nach und nach ints einfügen, so dass das array sortiert bleibt. Dabei können auch Werte zweimal auftreten. Also im Prinzip wie eine multimap, oder?</p>
<p>Hat da jemand Code für?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2208749</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2208749</guid><dc:creator><![CDATA[ggggggggggggggggg]]></dc:creator><pubDate>Sun, 06 May 2012 10:30:08 GMT</pubDate></item><item><title><![CDATA[Reply to sortiertes array of ints on Sun, 06 May 2012 10:34:23 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">int main()
{
	multiset&lt;int&gt; ms;

	ms.insert(32);
	ms.insert(564);
	ms.insert(232);
	ms.insert(1);
	ms.insert(0);

	for(multiset&lt;int&gt;::const_iterator it=ms.begin(); it!=ms.end(); ++it)
	{
		cout &lt;&lt; *it &lt;&lt; '\n';
	}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2208752</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2208752</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Sun, 06 May 2012 10:34:23 GMT</pubDate></item><item><title><![CDATA[Reply to sortiertes array of ints on Sun, 06 May 2012 10:35:58 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include&lt;set&gt;
</code></pre>
<p>edit: Zu langsam.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2208754</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2208754</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sun, 06 May 2012 10:35:58 GMT</pubDate></item><item><title><![CDATA[Reply to sortiertes array of ints on Sun, 06 May 2012 10:37:05 GMT]]></title><description><![CDATA[<p>KOmmt drauf an, was du brauchst: Assoziative oder Sequentielle Container. Eig. Brauchst du aber ein <code>std::multiset</code> , du kannst aber auch eine <code>std::list</code> nehmen und sortieren...</p>
<p>Edit: Auch zu langsam ... hyperaktive Forenuser.. <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/2208757</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2208757</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Sun, 06 May 2012 10:37:05 GMT</pubDate></item><item><title><![CDATA[Reply to sortiertes array of ints on Sun, 06 May 2012 10:38:04 GMT]]></title><description><![CDATA[<p><a href="http://en.cppreference.com/w/cpp/algorithm" rel="nofollow">http://en.cppreference.com/w/cpp/algorithm</a><br />
Guck dir da mal die &quot;Binary search operations (on sorted ranges)&quot; Funktionen an. Bedenke aber, dass du auf einem Array die Elemente eventuell verschieben musst. Insofern dürfte die Suche etwas schneller sein, das Einfügen von Elementen aber nicht. Und das Verhältnis verschiebt sich zu Gunsten von multiset je mehr Elemente du hast.</p>
<p>Edit: Argh, der Letzte. oO</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2208758</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2208758</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Sun, 06 May 2012 10:38:04 GMT</pubDate></item><item><title><![CDATA[Reply to sortiertes array of ints on Sun, 06 May 2012 11:22:30 GMT]]></title><description><![CDATA[<p>Warum so umständlich? Ich hätte dafür jetzt einfach std::inplace_merge missbraucht:</p>
<pre><code class="language-cpp">#include &lt;algorithm&gt;
#include &lt;cstdlib&gt;
#include &lt;ctime&gt;
#include &lt;iostream&gt;
#include &lt;iterator&gt;

int main() {
  int array[1000];
  size_t n;

  std::srand(std::time(0));

  for(n = 0; n &lt; 100; ++n) {
    // Element hinten anfügen; der vordere Teil ist sortiert, und das neue Element
    // kann als sortiertes Teilarray aufgefasst werden, womit die Voraussetzungen
    // für std::inplace_merge gegeben sind.

    array[n] = rand() % 10000;
    std::inplace_merge(array, array + n, array + n + 1);
  }

  std::copy(array, array + n, std::ostream_iterator&lt;int&gt;(std::cout, &quot;\n&quot;));
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2208775</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2208775</guid><dc:creator><![CDATA[seldon]]></dc:creator><pubDate>Sun, 06 May 2012 11:22:30 GMT</pubDate></item><item><title><![CDATA[Reply to sortiertes array of ints on Sun, 06 May 2012 12:08:55 GMT]]></title><description><![CDATA[<p>seldon schrieb:</p>
<blockquote>
<p>Warum so umständlich? Ich hätte dafür jetzt einfach std::inplace_merge missbraucht:</p>
<pre><code class="language-cpp">#include &lt;algorithm&gt;
#include &lt;cstdlib&gt;
#include &lt;ctime&gt;
#include &lt;iostream&gt;
#include &lt;iterator&gt;

int main() {
  int array[1000];
  size_t n;

  std::srand(std::time(0));

  for(n = 0; n &lt; 100; ++n) {
    // Element hinten anfügen; der vordere Teil ist sortiert, und das neue Element
    // kann als sortiertes Teilarray aufgefasst werden, womit die Voraussetzungen
    // für std::inplace_merge gegeben sind.

    array[n] = rand() % 10000;
    std::inplace_merge(array, array + n, array + n + 1);
  }

  std::copy(array, array + n, std::ostream_iterator&lt;int&gt;(std::cout, &quot;\n&quot;));
}
</code></pre>
</blockquote>
<p>Danke, das hab ich gesucht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2208787</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2208787</guid><dc:creator><![CDATA[originalposter]]></dc:creator><pubDate>Sun, 06 May 2012 12:08:55 GMT</pubDate></item></channel></rss>