|
[Tree-hh] Why no root node?Shan Gao gaoshan2002 at gmail.comMon Nov 9 23:36:32 GMT 2009
re-send this, in case not show up in mail list. It seems breadth first iterator doesn't work. It only access all nodes under the first top level node. tree<std::string> tr; std::cout << "empty tree to begin with:" << std::endl; print_tree(tr, tr.begin(), tr.end()); tr.insert(tr.end(), "1"); tr.insert(tr.end(), "2"); tr.insert(tr.end(), "3"); tr.insert(tr.end(), "4"); std::cout<< "bfi printing..." << std::endl; for (tree<std::string>::breadth_first_iterator bfi(tree<std::string>::iterator_base(tr.begin().node)); bfi != tr.end(); bfi++) { std::cout<< *bfi << std::endl; } This results in segment fault. I am still not sure how to do conversion among these different types of iterators safely. On Fri, Nov 6, 2009 at 2:23 AM, Kasper Peeters <kasper.peeters at durham.ac.uk>wrote: > Hi Shan, > > > My question is why there is no root node? This tree class looks more > > like a forest. > > Feel free to call it a forest if that helps you understand the > structure. I simply decided to have the option of more than one node > at the top, but you are free to never use that facility (i.e. just > call 'set_head' to insert a root node and then only append children to > that node, not siblings). It wasn't really a deep design issue. > > > The problem I got is there is no universal way to access all nodes, > because > > the nodes in the top level has no parent. > > I don't understand. What's wrong with simply iterating over all nodes > from begin() to end() ? That will visit everything, including the > nodes at the top level. > > Cheers, > Kasper > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.hepforge.org/lists-archive/tree-hh/attachments/20091109/03cae994/attachment.htm
More information about the Tree-hh mailing list |