[Cs3] breadth-first traversal in genealogy example
Mikhail Nesterenko
mikhail at cs.kent.edu
Tue Nov 12 15:37:44 EST 2019
CS3 students,
There is nothing mysterious about BFS and it can be implemented using
the Composite Design Pattern. BFS needs a global queue.
It can be a static member in Person class. The BFS pseudocode for
Woman::accept(PersonVisitor *visitor) could be this:
visitor->visit(this);
for(auto child : children_) {
que.push(child);
}
auto next=que.front();
que.pop();
next->accept();
Thanks,
--
Mikhail
More information about the cs3
mailing list