M
Mikito Harakiri
I have a tree modeled like this
class Node {
private Vector children = new Vector(); //
children.elementAt(i).getType() == Node.class
private Node parent = null;
}
I want to write a method nextLeaf(). It's very easy to write a Node's method
that makes recursive depth-first enumeration:
public void walkSubTree() {
for( int i = 0; i < children.size(); i++ )
walkSubTree(children.elementAt(i));
}
Now, I wonder how can I reconciliate recursive nature of "server" function
walkSubTree() with a "client" function nextLeaf() need to receive nodes
supplied by walkSubTree() in a "discontinous" manner. If after finding a
leaf could I save the recursion state somehow...
class Node {
private Vector children = new Vector(); //
children.elementAt(i).getType() == Node.class
private Node parent = null;
}
I want to write a method nextLeaf(). It's very easy to write a Node's method
that makes recursive depth-first enumeration:
public void walkSubTree() {
for( int i = 0; i < children.size(); i++ )
walkSubTree(children.elementAt(i));
}
Now, I wonder how can I reconciliate recursive nature of "server" function
walkSubTree() with a "client" function nextLeaf() need to receive nodes
supplied by walkSubTree() in a "discontinous" manner. If after finding a
leaf could I save the recursion state somehow...