<?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 Leute,</p>
<p>ich komme mit der Implementierung der folgenden Methode nicht klar, kann mir jemand helfen, es geht um Prioritätswarteschlange als Heap</p>
<p>void PriorityQueue::Insert(const PQElement&amp; anew){}</p>
<pre><code class="language-cpp">class PriorityQueue {
          int n;              // aktuelle Laenge
          int length;         // Gesamtlaenge=Aufnahmekapazitaet
          PQelement *a;       // fuer das Feld

    public:
          int l;

          void PriorityQueue(int l=1000){
            int length = l;
            int n = 0;
            int a = new PQElement[length];
          }

          PQElement&amp; Maximum(void) const; 

          PQElement Extract_Max(void);

          void DownHeap(int i, int n, int a[n]);

          void Insert(const PQElement&amp; anew);//Liefert a[1].

          //liefert das bzw. eines der Elemente mit der höchsten Priorität
          void Maximum();

          void ExtractMax();

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/296139/heap</link><generator>RSS for Node</generator><lastBuildDate>Sat, 15 Aug 2026 04:20:34 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/296139.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 28 Nov 2011 19:12:34 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Heap on Mon, 28 Nov 2011 19:12:34 GMT]]></title><description><![CDATA[<p>Hallo Leute,</p>
<p>ich komme mit der Implementierung der folgenden Methode nicht klar, kann mir jemand helfen, es geht um Prioritätswarteschlange als Heap</p>
<p>void PriorityQueue::Insert(const PQElement&amp; anew){}</p>
<pre><code class="language-cpp">class PriorityQueue {
          int n;              // aktuelle Laenge
          int length;         // Gesamtlaenge=Aufnahmekapazitaet
          PQelement *a;       // fuer das Feld

    public:
          int l;

          void PriorityQueue(int l=1000){
            int length = l;
            int n = 0;
            int a = new PQElement[length];
          }

          PQElement&amp; Maximum(void) const; 

          PQElement Extract_Max(void);

          void DownHeap(int i, int n, int a[n]);

          void Insert(const PQElement&amp; anew);//Liefert a[1].

          //liefert das bzw. eines der Elemente mit der höchsten Priorität
          void Maximum();

          void ExtractMax();

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2150155</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2150155</guid><dc:creator><![CDATA[julchatt]]></dc:creator><pubDate>Mon, 28 Nov 2011 19:12:34 GMT</pubDate></item><item><title><![CDATA[Reply to Heap on Mon, 28 Nov 2011 19:17:34 GMT]]></title><description><![CDATA[<p>Wo genau ist das Problem?<br />
Weisst du wie es theoretisch geht?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2150158</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2150158</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Mon, 28 Nov 2011 19:17:34 GMT</pubDate></item><item><title><![CDATA[Reply to Heap on Mon, 28 Nov 2011 19:26:47 GMT]]></title><description><![CDATA[<p>theoretisch weiß ich es, aber mit der Umsetzung in c++ hapert es ziemlich stark...</p>
<p>also diese insert Methode muss ein neues Element am Ende der Schlange einfügen, dabei muss sie per Random() die Priorität zugewiesen werden und anschließend per upHeap die Heapeigenschaft wieder herstellen...und die Random Klasse ist hier...</p>
<pre><code class="language-cpp">Random::Random(int r = -1) // Defaultparameter
{
	max_range = r;
	fill_mask = 0;
	fill_bits = 0;
	/* determine no. of bits required */
	if (max_range &gt; RAND_MAX) {
		int req_padding = (max_range / RAND_MAX);
		//cout &lt;&lt; &quot;Required padding is: &quot; &lt;&lt; req_padding &lt;&lt; endl;
		int cur_padding = 1;
		while (cur_padding &lt; req_padding) {
			cur_padding = cur_padding &lt;&lt; 1;
			fill_mask = fill_mask &lt;&lt; 1;
			fill_mask += 1;
			fill_bits++;
		}
	}
	//cout &lt;&lt; &quot;No. of fill bits is: &quot; &lt;&lt; fill_bits &lt;&lt; endl;
	//cout &lt;&lt; &quot;Fill mask is: &quot; &lt;&lt; fill_mask &lt;&lt; endl;
	//srand(clock());
	srand (12);
}

Random::~Random()
{
}

int Random::give()
{
	int value = rand();
	int sec_value = rand();

	for (int i = 1; i &lt;= fill_bits; i++) {
		value = value &lt;&lt; 1;
	}
	value += (sec_value &amp;&amp;  fill_mask);
	return (value % max_range);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2150165</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2150165</guid><dc:creator><![CDATA[julchatt]]></dc:creator><pubDate>Mon, 28 Nov 2011 19:26:47 GMT</pubDate></item></channel></rss>