eachAfter method
εεΊιε
Implementation
T eachAfter(TreeFun<T> callback) {
List<T> nodes = [this as T];
List<T> next = [];
List<T> children;
int index = -1;
while (nodes.isNotEmpty) {
T node = nodes.removeAt(nodes.length - 1);
next.add(node);
children = node._childrenList;
if (children.isNotEmpty) {
int n = children.length;
for (int i = 0; i < n; ++i) {
nodes.add(children[i]);
}
}
}
while (next.isNotEmpty) {
TreeNode node = next.removeAt(next.length - 1);
if (callback.call(node as T, ++index, this as T)) {
break;
}
}
return this as T;
}