addReachable method

void addReachable(
  1. Node startNode
)

Adds all nodes and edges reachable from this node to the subgraph. Uses an explicit stack to avoid a large depth of recursion.

@param node a node known to be in the subgraph

Implementation

void addReachable(Node startNode) {
  Queue nodeStack = new Queue();
  nodeStack.add(startNode);
  while (!nodeStack.isEmpty) {
    Node node = nodeStack.removeLast();
    add(node, nodeStack);
  }
}