isAncestorOf static method

bool isAncestorOf(
  1. Tree? t,
  2. Tree? u
)

Return true if t is u's parent or a node on path to root from u. Use == not equals().

@since 4.5.1

Implementation

static bool isAncestorOf(Tree? t, Tree? u) {
  if (t == null || u == null || t.parent == null) return false;
  var p = u.parent;
  while (p != null) {
    if (t == p) return true;
    p = p.parent;
  }
  return false;
}