Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breadth-first iterators do not work on multiple heads tree. #10

Open
rdebroiz opened this issue Mar 3, 2021 · 1 comment
Open

Breadth-first iterators do not work on multiple heads tree. #10

rdebroiz opened this issue Mar 3, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@rdebroiz
Copy link

rdebroiz commented Mar 3, 2021

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
@rdebroiz
Copy link
Author

rdebroiz commented Mar 3, 2021

It does work if the tree as a single head.

@rdebroiz rdebroiz changed the title Breadth-first iterators do not work. Breadth-first iterators do not work on multiple heads tree. Mar 3, 2021
@kpeeters kpeeters added the bug Something isn't working label Feb 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants