Skip to content

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

@rdebroiz

Description

@rdebroiz

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions