<?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[Heap]]></title><description><![CDATA[<p>Hallo miteinander</p>
<p>Ich habe eine Verständnis-Frage:<br />
Wenn ich sowas habe:<br />
return heap[1].second;</p>
<p>und die heaps so gefüllt werden:<br />
heap.insertItem(3, &quot;apple&quot;);</p>
<p>Dann ist heap[1].first = 3 und heap[1].second = &quot;apple&quot;, oder?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/287918/heap</link><generator>RSS for Node</generator><lastBuildDate>Thu, 20 Aug 2026 05:04:22 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/287918.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 07 Jun 2011 09:29:35 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Heap on Tue, 07 Jun 2011 09:29:35 GMT]]></title><description><![CDATA[<p>Hallo miteinander</p>
<p>Ich habe eine Verständnis-Frage:<br />
Wenn ich sowas habe:<br />
return heap[1].second;</p>
<p>und die heaps so gefüllt werden:<br />
heap.insertItem(3, &quot;apple&quot;);</p>
<p>Dann ist heap[1].first = 3 und heap[1].second = &quot;apple&quot;, oder?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2074502</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2074502</guid><dc:creator><![CDATA[SonjaZ]]></dc:creator><pubDate>Tue, 07 Jun 2011 09:29:35 GMT</pubDate></item><item><title><![CDATA[Reply to Heap on Tue, 07 Jun 2011 09:48:41 GMT]]></title><description><![CDATA[<p>SonjaZ schrieb:</p>
<blockquote>
<p>Hallo miteinander</p>
<p>Ich habe eine Verständnis-Frage:<br />
Wenn ich sowas habe:<br />
return heap[1].second;</p>
<p>und die heaps so gefüllt werden:<br />
heap.insertItem(3, &quot;apple&quot;);<br />
Dann ist heap[1].first = 3 und heap[1].second = &quot;apple&quot;, oder?</p>
</blockquote>
<p>Wenn Du sagst, woher heap kommt, aus welcher API, aus welchem Lehrbuch oder woher? Dann könnte ich es vielleicht herausfinden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2074510</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2074510</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Tue, 07 Jun 2011 09:48:41 GMT</pubDate></item><item><title><![CDATA[Reply to Heap on Tue, 07 Jun 2011 09:53:58 GMT]]></title><description><![CDATA[<p>Es kommt von privat. Aber was noch hilfreich wäre: Folgendes wird noch definiert:<br />
typedef pair&lt;Key, Element&gt; Item;<br />
vector&lt;Item&gt; heap;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2074512</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2074512</guid><dc:creator><![CDATA[SonjaZ]]></dc:creator><pubDate>Tue, 07 Jun 2011 09:53:58 GMT</pubDate></item><item><title><![CDATA[Reply to Heap on Tue, 07 Jun 2011 10:02:51 GMT]]></title><description><![CDATA[<p>SonjaZ schrieb:</p>
<blockquote>
<p>Es kommt von privat. Aber was noch hilfreich wäre: Folgendes wird noch definiert:<br />
typedef pair&lt;Key, Element&gt; Item;<br />
vector&lt;Item&gt; heap;</p>
</blockquote>
<p>Deine Vermutung mit first und second ist höchst wahrscheinlich wahr.<br />
Es kommt nicht von privat.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2074515</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2074515</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Tue, 07 Jun 2011 10:02:51 GMT</pubDate></item><item><title><![CDATA[Reply to Heap on Tue, 07 Jun 2011 11:59:22 GMT]]></title><description><![CDATA[<p>Ok, besten Dank!<br />
Da ich diese &quot;Konvention&quot; eben nirgends gelesen habe, war ich mir nicht ganz sicher. Allerdings würde der Code (für mich) keinen Sinn machen, wenn dies irgendwie anders wäre.</p>
<p>Liebe Grüsse und danke,<br />
Sonja</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2074600</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2074600</guid><dc:creator><![CDATA[SonjaZ]]></dc:creator><pubDate>Tue, 07 Jun 2011 11:59:22 GMT</pubDate></item><item><title><![CDATA[Reply to Heap on Tue, 07 Jun 2011 12:16:47 GMT]]></title><description><![CDATA[<p>Wenn ich das richtig verstehe, dann wird an dieser Stelle:</p>
<pre><code class="language-cpp">heap.insertItem(3, &quot;apple&quot;);
</code></pre>
<p>implizit der Konstruktor <code>pair&lt;Value,Key&gt;(Value, Key)</code> aufgerufen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2074608</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2074608</guid><dc:creator><![CDATA[bmario]]></dc:creator><pubDate>Tue, 07 Jun 2011 12:16:47 GMT</pubDate></item><item><title><![CDATA[Reply to Heap on Tue, 07 Jun 2011 12:35:10 GMT]]></title><description><![CDATA[<p>Müsste das bei einem einelementigen heap nicht heap[0] heissen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2074622</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2074622</guid><dc:creator><![CDATA[DocShoe]]></dc:creator><pubDate>Tue, 07 Jun 2011 12:35:10 GMT</pubDate></item><item><title><![CDATA[Reply to Heap on Tue, 07 Jun 2011 13:22:57 GMT]]></title><description><![CDATA[<p>DocShoe schrieb:</p>
<blockquote>
<p>Müsste das bei einem einelementigen heap nicht heap[0] heissen?</p>
</blockquote>
<p>Vermutlich. Vielleicht aus einem Algorithmenbuch geholt, das für Pascal war. Mit heap[1] gibt's hübschere Tafelbildchen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2074660</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2074660</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Tue, 07 Jun 2011 13:22:57 GMT</pubDate></item><item><title><![CDATA[Reply to Heap on Tue, 07 Jun 2011 14:06:40 GMT]]></title><description><![CDATA[<p>SonjaZ schrieb:</p>
<blockquote>
<p>typedef pair&lt;Key, Element&gt; Item;<br />
vector&lt;Item&gt; heap;</p>
</blockquote>
<p>Was ist Key und was ist Element?<br />
Ich rate: Key=int und Element=std::string</p>
<p>SonjaZ schrieb:</p>
<blockquote>
<p>Wenn ich sowas habe:<br />
return heap[1].second;</p>
<p>und die heaps so gefüllt werden:<br />
heap.insertItem(3, &quot;apple&quot;);</p>
</blockquote>
<p>heap ist nur ein Name. In diesem Fall bezieht sich der Name auf ein vector&lt;Item&gt;-Objekt, wobei Item synonym zu pair&lt;Key,Element&gt; ist. Mit anderen Worten, der Vektor speichert Key/Element-Paare. Ein solcher Vektor bietet aber keine Funktion mit Namen &quot;insertItem&quot; an.</p>
<p>Das Einfügen könnte so aussehen:</p>
<pre><code class="language-cpp">heap.insert(pos,Item(3,&quot;apple&quot;));
</code></pre>
<p>wobei <code>pos</code> ein Iterator ist, der die Einfüge-Position angibt.</p>
<p>SonjaZ schrieb:</p>
<blockquote>
<p>Dann ist heap[1].first = 3 und heap[1].second = &quot;apple&quot;, oder?</p>
</blockquote>
<p>Diese Frage kann man Dir erst beantworten, wenn Du kompilierbaren Code zeigst. Nebenbei: Der Index für das erste Element eines Vektors ist 0.</p>
<p>Schau in Dein C++ Lehrbuch oder auch auf der Seite <a href="http://www.cplusplus.com/reference/" rel="nofollow">http://www.cplusplus.com/reference/</a> nach, wie Vektoren (std::vector) und Pair (std::pair) funktioniert bzw benutzbar ist. Das Klassen-Template vector wird in der Kopfdatei &lt;header&gt; und pair wird in &lt;utility&gt; definiert.</p>
<p>Ja, ein pair-Objekt besitzt zwei Datenelemente: first und second.</p>
<p><a href="http://ideone.com/0rYWZ" rel="nofollow">So</a> sieht ein kompilierbares Beispiel aus:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;ostream&gt;
#include &lt;string&gt;
#include &lt;utility&gt;
#include &lt;vector&gt;

using namespace std;

typedef int Key;
typedef string Element;
typedef pair&lt;Key,Element&gt; Item;

int main()
{
  vector&lt;Item&gt; heap;
  heap.push_back(Item(42,&quot;forty-two&quot;));
  cout &lt;&lt; heap[0].first &lt;&lt; endl;
  cout &lt;&lt; heap[0].second &lt;&lt; endl;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2074673</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2074673</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Tue, 07 Jun 2011 14:06:40 GMT</pubDate></item></channel></rss>