tree walking -- saved recursion state

From: Mikito Harakiri (mikharakiri_at_iahu.com)
Date: 01/05/04

  • Next message: Bart Demoen: "Re: tree walking -- saved recursion state"
    Date: Mon, 5 Jan 2004 09:38:25 -0800
    
    

    I have a tree:

    class Node {
        private Vector children = new Vector();
        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...


  • Next message: Bart Demoen: "Re: tree walking -- saved recursion state"