Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is <a href="http://www.aei.mpg.de/~peekas/tree/" rel="noreferrer">tree.hh</a> which is a bit close to what you want to do, though a bit different.</p> <p>Here is a piece of code extracted from its website.</p> <pre><code>int main(int, char **) { tree&lt;string&gt; tr; tree&lt;string&gt;::iterator top, one, two, loc, banana; top=tr.begin(); one=tr.insert(top, "one"); two=tr.append_child(one, "two"); tr.append_child(two, "apple"); banana=tr.append_child(two, "banana"); tr.append_child(banana,"cherry"); tr.append_child(two, "peach"); tr.append_child(one,"three"); loc=find(tr.begin(), tr.end(), "two"); if(loc!=tr.end()) { tree&lt;string&gt;::sibling_iterator sib=tr.begin(loc); while(sib!=tr.end(loc)) { cout &lt;&lt; (*sib) &lt;&lt; endl; ++sib; } cout &lt;&lt; endl; tree&lt;string&gt;::iterator sib2=tr.begin(loc); tree&lt;string&gt;::iterator end2=tr.end(loc); while(sib2!=end2) { for(int i=0; i&lt;tr.depth(sib2)-2; ++i) cout &lt;&lt; " "; cout &lt;&lt; (*sib2) &lt;&lt; endl; ++sib2; } } } </code></pre> <p>Now what's different? Your implementation is simpler when it comes to append a node to the tree. Though your version is indiscutably simpler, the dev of this lib probably wanted to have some info accessible without browsing the tree, such as the size of the tree for instance.</p> <p>I also assume he didn't want to store the root on all nodes for performance reason. So if you want to implement it your way, I suggest you keep most of the logic and add the link to the parent tree in the iterator and rewrite append a bit.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload