The output from the following code is incorrect. It should only output the leaves in the tree:
tree<Node> gameTree;
tree<Node>::iterator root = gameTree.insert(gameTree.begin(),Node(14));
tree<Node>::iterator first = gameTree.append_child(root,Node(32.0));
tree<Node>::iterator second = gameTree.append_child(root,Node(64.0));
gameTree.append_child(second,Node(21.0));
gameTree.append_child(second,Node(24.0));
tree<Node>::iterator begin = gameTree.begin_leaf();
tree<Node>::iterator end = gameTree.end_leaf();
int x = 0;
while (begin != end)
{
cout << begin->value << endl;
begin++;
}
But it outputs:
32
64
21
24
when the output SHOULD be:
32
21
24
From the docs you should be using a leaf_iterator rather than an iterator, the output you’re seeing is from an in order traversal, you want to do a leaf traversal I’m guessing.
btw, thanks for posting this I was just starting in a search for a tree container
hth