visit method

void visit(
  1. void f(
    1. TreeNode<T> node
    )
)

Applies the function f to all child nodes rooted from this node in breadth first order.

Implementation

void visit(void Function(TreeNode<T> node) f) {
  final queue = Queue<TreeNode<T>>()..add(this);

  while (queue.isNotEmpty) {
    final node = queue.removeFirst();
    f(node);
    queue.addAll(node.children);
  }
}