getMaxDepth method

int getMaxDepth()

Get the depth of this node.

If it has no children, its depth is simply 1. Otherwise, find the highest depth based on its child nodes.

Implementation

int getMaxDepth() {
  if (children.isEmpty) {
    return 1;
  } else {
    List<int> depths = List.generate(children.length, (index) => 1);
    for (var (index, child) in children.indexed) {
      depths[index] += child.getMaxDepth();
    }
    return depths.max;
  }
}