<!DOCTYPE html><html><body><div dir="auto">Hi David,<br><br>Traversing a tree without recursion usually required keeping a stack you can push onto and pop when you hit a leaf. This is all handled for you in the call stack when you use recursion. If you really do want to avoid recursion, I would recommend having a look at general strategies for tree traversal without recursion. Something like:<br><br><a href="https://www.geeksforgeeks.org/inorder-tree-traversal-without-recursion/">https://www.geeksforgeeks.org/inorder-tree-traversal-without-recursion/</a><br><br>With recursion, our TreeIndexUtil printTree function serves as a great example:<br><br><a href="https://crosswire.org/svn/sword/trunk/utilities/treeidxutil.cpp">https://crosswire.org/svn/sword/trunk/utilities/treeidxutil.cpp</a><br><br>Hope this helps. Blessings in your work,<br><br>Troy<br><br><br><br><br>On 3/5/24 10:13, David "Judah's Shadow" Blue wrote:<br>> On Monday, March 4, 2024 4:32:43 PM EST David "Judah's Shadow" Blue wrote:<br>>> Ok, I think I have a handle on how to generate the TOC. However, I'm not<br>>> seeing a method in the API docs that would give me the text for a given TOC<br>>> entry<br>> Well I thought i had a handle on generating a TOC, but I'm only getting down<br>> one branch. I want to avoid recursion if I can, but I can't figure out how to<br>> get back up the tree to traverse down the next branch. If I have to use<br>> recursion I can, but I'd really like to avoid it. Here's my code so far.<br>> <br>> std::string Genbook::getTOC() {<br>> sword::TreeKey *treeKey;<br>> sword::SWModule *mod;<br>> std::string toc = "";<br>> <br>> mod = swordLibrary->getModule(book.c_str());<br>> <br>> //Assume we don't have a TreeKey yet since we're just starting.<br>> treeKey = dynamic_cast<sword::TreeKey*>(mod->getKey());<br>> <br>> if(treeKey->firstChild()) {<br>> while(treeKey->nextSibling()) {<br>> toc += treeKey->getText();<br>> toc += "\n";<br>> if(treeKey->hasChildren()) {<br>> treeKey->increment();<br>> }<br>> }<br>> }<br>> <br>> return toc;<br>> <br>> }<br>> <br>> <br>> <br>> _______________________________________________<br>> sword-devel mailing list: sword-devel@crosswire.org<br>> <a href="http://crosswire.org/mailman/listinfo/sword-devel">http://crosswire.org/mailman/listinfo/sword-devel</a><br>> Instructions to unsubscribe/change your settings at above page<br></div><div dir="auto"><div class='k9mail-signature'>-- <br>Sent from my Android device with K-9 Mail. Please excuse my brevity.</div></div></body></html>