Finding all subtrees in a binary tree
I need to store all of the subtrees of a binary tree into an array of lists of vertices, where each list in the array of lists is a subtree (root and all of its descendants). A recursive traversal is probably best(?).

So if we have
<pre><code>

    class Vertex {
            int index;
            Vertex left;
            Vertex right;
            Vertex (int index, Vertex left, Vertex right){...init vars....}
        }

</pre></code>
I need to generate an <code>ArrayList&lt;ArrayList&lt;Vertex&gt;&gt; subtreeList </code>that stores all of the descendent vertices of each vertex (taken as the root), where subtreeList.get(vertex.index).add(vertex and all its descendents). Sorry for the poor wording, I find this difficult to articulate. Help appreciated.




Finding all subtrees in a binary tree
===

I need to store all of the subtrees of a binary tree into an array of lists of vertices, where each list in the array of lists is a subtree (root and all of its descendants). A recursive traversal is probably best(?).

So if we have
<pre><code>

    class Vertex {
            int index;
            Vertex left;
            Vertex right;
            Vertex (int index, Vertex left, Vertex right){...init vars....}
        }

</pre></code>
I need to generate an <code>ArrayList&lt;ArrayList&lt;Vertex&gt;&gt; subtreeList </code>that stores all of the descendent vertices of each vertex (taken as the root), where subtreeList.get(vertex.index).add(vertex and all its descendents). Sorry for the poor wording, I find this difficult to articulate. Help appreciated.



