tree.hh
tree.hh copied to clipboard
Breadth-first iterators do not work on multiple heads tree.
The doc says that for the tree:
root
|
+----A
| |
| +---B
| |
| +---C
|
+----D
|
+---E
|
+---F
The resulting order in which nodes are visited using breadth_first_iterator
is: root A D B C E F
.
But it's A B C
tree<char> t;
auto r = t.insert(t.begin(), 'A');
auto it = t.append_child(r, 'B');
it = t.insert_after(it, 'C');
it = t.insert_after(r, 'D');
it = t.append_child(it, 'E');
it = t.insert_after(it, 'F');
auto bfit = t.begin_breadth_first();
cout << "breadthfirst from root: ";
while(t.is_valid(bfit)) {
cout << *bfit << " ";
++bfit;
}
cout << endl;
tree<char>::sibling_iterator siit = t.begin();
cout << "siblings from root: ";
while(t.is_valid(siit)) {
cout << *siit << " ";
++siit;
}
cout << endl;
output:
breadthfirst from root: A B C // Not OK
siblings from root: A D // OK
It does work if the tree as a single head.