kpeeters / tree.hh

An STL-like C++ header-only tree library
GNU General Public License v3.0
132 stars 31 forks source link

Can you provide an example of doing recursion with the default depth first iterator #2

Closed HSchmale16 closed 5 years ago

HSchmale16 commented 5 years ago

Hello I'm wondering if you could provide an example of using your tree.hh class in a recursive manner for doing a pre-order traversal? I need a way to keep existing scope around for the current list while popping stuff off.

I've looked all over the internet for a method to do so, but have not found an example with your class.

kpeeters commented 5 years ago

Why do you want to do this recursively? If you just do

auto it=tr.begin();
while(it!=tr.end()) {
     /* do something with 'it' */
    ++it;
    }

the iterator will take care of visiting all nodes. What precisely do you mean with 'I need a way to keep ... while popping stuff off'?