getRoot method

Node getRoot()

Returns the root node of the graph that this node is a part of.

Implementation

Node getRoot() {
  Node? current = this;
  while (current!._parent != null) {
    current = current._parent;
  }
  return current;
}