I`m writing binary search tree template for two reasons – learning C++ and learning most common algorithms and data structures.
So, here is the question – as long as I want to implement iterators, it seems to me that there is no strict definition for where tree ends. What are your suggestions? How do I do this?
I`m writing binary search tree template for two reasons – learning C++ and learning
Share
For trees, there are standards for traversing the tree, i.e. enumerating the nodes: Preorder traversal, inorder traversal, and postorder traversal. Rather than describe all these here, I’ll redirect you to http://en.wikipedia.org/wiki/Tree_traversal. The concepts are mostly applied to binary trees, but you can extend the idea to arbitrary trees by adding more cases: Effectively, handle a node then recurse, recurse then handle a node, handle all children then recurse into each…etc. There’s no canonical categorization of this approach that I’m aware of.