public static <D>void iterateDfs(D rootData,NodeDataAdapter<D> dataAdapter,Visitor<D> callback){
  LinkedList<D> nodes=new LinkedList<>();
  nodes.add(rootData);
  while (!nodes.isEmpty()) {
    D parentNodeData=nodes.pop();
    boolean willVisitChildren=false;
    List<D> children=dataAdapter.getChildren(parentNodeData);
    for (int i=0, n=children.size(); i < n; i++) {
      D child=children.get(i);
      if (callback.shouldVisit(child)) {
        nodes.add(child);
        willVisitChildren=true;
      }
    }
    callback.visit(parentNodeData,willVisitChildren);
  }
}

public static < D > void iterateDfs ( D rootData , NodeDataAdapter < D > dataAdapter , Visitor < D > callback ) { LinkedList < D > nodes = new LinkedList < > ( ) ; nodes . add ( rootData ) ; while ( ! nodes . isEmpty ( ) ) { D parentNodeData = nodes . pop ( ) ; boolean willVisitChildren = false ; List < D > children = dataAdapter . getChildren ( parentNodeData ) ; for ( int i = 0 , n = children . size ( ) ; i < n ; i ++ ) { D child = children . get ( i ) ; if ( callback . shouldVisit ( child ) ) { nodes . add ( child ) ; willVisitChildren = true ; } } callback . visit ( parentNodeData , willVisitChildren ) ; } }
recursively iterates children of a given root node using dfs .
