<?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[BinaryTreeNode - wie funktioniert das?]]></title><description><![CDATA[<p>Hallo,</p>
<p>vielleicht könnt ihr mir weiterhelfen.</p>
<p>Ich habe folgende Klasse:</p>
<pre><code class="language-cpp">class BinaryTreeNode{

   private:
     int content; // Data
     BinaryTreeNode *l_next; // left successor
     BinaryTreeNode *r_next; // right successor

   public:

     BinaryTreeNode(int content){
        this-&gt;content = content;
        l_next = TNULL;
        r_next = TNULL;
     }// end constructor
     // ggf. weitere Konstruktoren

     int countNodes(){
        return countNodes(this);
     }// end countNodes()

     int treeHeight(){
        return treeHeight(this);
     }// end treeHeight()

     // weitere Methoden

};// end of class BinaryTreeNode
</code></pre>
<p>Nun sollen für diese Klasse z.B. rekursive private Methoden codiert werden.<br />
Zum Beispiel um die Anzahl der Nodes zu berechnen oder die Baumhöhe.<br />
Zusätzlich eine Funktion um neue Nodes aufzunehmen.</p>
<p>Ich verstehe nur Bahnhof, kann man hier jemand einen Denkanstoß geben?</p>
<p>Grüße</p>
<p>//Edit: CodeTags</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/257072/binarytreenode-wie-funktioniert-das</link><generator>RSS for Node</generator><lastBuildDate>Wed, 15 Apr 2026 06:26:43 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/257072.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 22 Dec 2009 11:53:29 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to BinaryTreeNode - wie funktioniert das? on Tue, 22 Dec 2009 13:05:45 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>vielleicht könnt ihr mir weiterhelfen.</p>
<p>Ich habe folgende Klasse:</p>
<pre><code class="language-cpp">class BinaryTreeNode{

   private:
     int content; // Data
     BinaryTreeNode *l_next; // left successor
     BinaryTreeNode *r_next; // right successor

   public:

     BinaryTreeNode(int content){
        this-&gt;content = content;
        l_next = TNULL;
        r_next = TNULL;
     }// end constructor
     // ggf. weitere Konstruktoren

     int countNodes(){
        return countNodes(this);
     }// end countNodes()

     int treeHeight(){
        return treeHeight(this);
     }// end treeHeight()

     // weitere Methoden

};// end of class BinaryTreeNode
</code></pre>
<p>Nun sollen für diese Klasse z.B. rekursive private Methoden codiert werden.<br />
Zum Beispiel um die Anzahl der Nodes zu berechnen oder die Baumhöhe.<br />
Zusätzlich eine Funktion um neue Nodes aufzunehmen.</p>
<p>Ich verstehe nur Bahnhof, kann man hier jemand einen Denkanstoß geben?</p>
<p>Grüße</p>
<p>//Edit: CodeTags</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1826311</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1826311</guid><dc:creator><![CDATA[hype_]]></dc:creator><pubDate>Tue, 22 Dec 2009 13:05:45 GMT</pubDate></item><item><title><![CDATA[Reply to BinaryTreeNode - wie funktioniert das? on Tue, 22 Dec 2009 12:01:04 GMT]]></title><description><![CDATA[<p>hype_ schrieb:</p>
<blockquote>
<p>Nun sollen für diese Klasse z.B. rekursive private Methoden codiert werden.<br />
Zum Beispiel um die Anzahl der Nodes zu berechnen oder die Baumhöhe.<br />
Zusätzlich eine Funktion um neue Nodes aufzunehmen.</p>
<p>Ich verstehe nur Bahnhof, kann man hier jemand einen Denkanstoß geben?</p>
<p>Grüße</p>
</blockquote>
<p>Traversier den Baum rekursiv und zaehl dabei mit, wieviel Nodes du besuchst bzw. wie tief du schon abgestiegen bist <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1826315</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1826315</guid><dc:creator><![CDATA[Blue-Tiger]]></dc:creator><pubDate>Tue, 22 Dec 2009 12:01:04 GMT</pubDate></item><item><title><![CDATA[Reply to BinaryTreeNode - wie funktioniert das? on Tue, 22 Dec 2009 12:03:06 GMT]]></title><description><![CDATA[<p>Okay, von der Theorie her klar, aber wie soll der Code dafür aussehen?<br />
Das blicke ich nicht.</p>
<p>Gibt es da irgendwo im Netz eine gute Anleitung mit Beispielen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1826319</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1826319</guid><dc:creator><![CDATA[hype_]]></dc:creator><pubDate>Tue, 22 Dec 2009 12:03:06 GMT</pubDate></item><item><title><![CDATA[Reply to BinaryTreeNode - wie funktioniert das? on Tue, 22 Dec 2009 12:18:12 GMT]]></title><description><![CDATA[<p>hype_ schrieb:</p>
<blockquote>
<p>Gibt es da irgendwo im Netz eine gute Anleitung mit Beispielen?</p>
</blockquote>
<p>Du verlangst aber jetzt nicht dass wir dir das Googlen abnehmen, nöch?<br />
<a href="http://google.de" rel="nofollow">google.de</a> weiß das nämlich sicher!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1826328</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1826328</guid><dc:creator><![CDATA[Popen]]></dc:creator><pubDate>Tue, 22 Dec 2009 12:18:12 GMT</pubDate></item><item><title><![CDATA[Reply to BinaryTreeNode - wie funktioniert das? on Tue, 22 Dec 2009 12:24:28 GMT]]></title><description><![CDATA[<p>hype_ schrieb:</p>
<blockquote>
<p>Okay, von der Theorie her klar, aber wie soll der Code dafür aussehen?</p>
</blockquote>
<p>Nur nicht verwirren lassen. Die Anzahl der Knoten in einem Baum ist Eins plus die Anzahl der Knoten im rechten Ast plus die Anzahl der Knoten im linken Ast.</p>
<p>Die Tiefe eines Baumes ohne Äste ist Eins. Die Tiefe eines Baumes mit Ästen ist Eins plus die Tiefe des tiefsten Astes.</p>
<p>hype_ schrieb:</p>
<blockquote>
<p>Zusätzlich eine Funktion um neue Nodes aufzunehmen.</p>
</blockquote>
<p>Das ist leicht, einfach zwei Knoten hernehmen und die Zeiger so umbiegen, dass der neue Knoten in der Mitte ist. Der Knackpunkt ist wahrscheinlich die Frage, wo denn der neue Knoten hin soll.<br />
<img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1826332</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1826332</guid><dc:creator><![CDATA[µngbd]]></dc:creator><pubDate>Tue, 22 Dec 2009 12:24:28 GMT</pubDate></item><item><title><![CDATA[Reply to BinaryTreeNode - wie funktioniert das? on Tue, 22 Dec 2009 13:42:34 GMT]]></title><description><![CDATA[<p>Okay, zuerst mal die insertNode.</p>
<pre><code class="language-cpp">BinaryTreeNode * insertNode(BinaryTreeNode *Blatt, int content)
{
    if (Blatt==0) 
    { 
        Blatt = new BinaryTreeNode(0);
        Blatt-&gt;l_next = Blatt-&gt;r_next = 0;
        Blatt-&gt;content = content;
        return Blatt; 
    }
    if (content &lt; Blatt-&gt;content)
    { 
        Blatt-&gt;l_next = insertNode(Blatt-&gt;l_next, content);
    }
    else if (content &gt; Blatt-&gt;content)
    { 
        Blatt-&gt;r_next = insertNode(Blatt-&gt;r_next, content);
    }
    return Blatt;
}
</code></pre>
<pre><code class="language-cpp">int treeHeight(BinaryTreeNode *Blatt)
{
    int zaehler = 0;
    zaehler++;
    if (Blatt==0) return zaehler;
    treeHeight(Blatt-&gt;l_next);

}
</code></pre>
<p>Im Main:</p>
<p>BinaryTreeNode *root = new BinaryTreeNode(0);<br />
root-&gt;insertNode(root, 1);</p>
<p>cout &lt;&lt; root-&gt;treeHeight(root);</p>
<p>Da kommt nun 4078912 raus, stimmt irgendwie nicht <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>
<p>//Edit: CodeTags</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1826347</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1826347</guid><dc:creator><![CDATA[hype_]]></dc:creator><pubDate>Tue, 22 Dec 2009 13:42:34 GMT</pubDate></item><item><title><![CDATA[Reply to BinaryTreeNode - wie funktioniert das? on Tue, 22 Dec 2009 14:06:06 GMT]]></title><description><![CDATA[<p>Hab es nun so gelöst:</p>
<pre><code class="language-cpp">int treeHeight(BinaryTreeNode *n)
	{
		if(n == NULL)
			return 0;
		else 
		{
			int hl = treeHeight(n-&gt;l_next);
			int hr = treeHeight(n-&gt;r_next);
			return (hl &gt; hr?  hl:  hr) + 1;
		}
	}

	   int countNodes(BinaryTreeNode *n)
	{
		if(n == NULL)
			return 0;
		else 
		{
			int hl = treeHeight(n-&gt;l_next);
			int hr = treeHeight(n-&gt;r_next);
			return (hl + hr + 1);
		}
	}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1826359</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1826359</guid><dc:creator><![CDATA[hype_]]></dc:creator><pubDate>Tue, 22 Dec 2009 14:06:06 GMT</pubDate></item><item><title><![CDATA[Reply to BinaryTreeNode - wie funktioniert das? on Tue, 22 Dec 2009 18:59:52 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">int countNodes(BinaryTreeNode *n)
    {
        if(n == NULL)
            return 0;
        else
        {
            int hl = treeHeight(n-&gt;l_next);
            int hr = treeHeight(n-&gt;r_next);
            return (hl + hr + 1);
        }
    }
</code></pre>
<p>Du meinst wahrscheinlich countNodes statt treeHeight:</p>
<pre><code class="language-cpp">int countNodes(BinaryTreeNode *n)
{
    return n ? 1 + countNodes(n-&gt;l_next) + countNodes(n-&gt;r_next) : 0;
}
</code></pre>
<p>Schade eigentlich, dass man mit Rekursionen in C++ vorsichtig sein muss.<br />
<img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1826552</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1826552</guid><dc:creator><![CDATA[µngbd]]></dc:creator><pubDate>Tue, 22 Dec 2009 18:59:52 GMT</pubDate></item></channel></rss>