Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Patricia Trie Traversal

809475Jun 25 2008 — edited Jul 8 2008
Hello all,

I have created a patricia tree (trie) using lists.
for eg. a trie node is implemented as follows:
class TrieNode<T> {
    private String key;

    private List<TrieNode<T>> children;

    private boolean real;

    private T value;
and the whole tree is implemented as:
public class TrieImpl<T> implements Trie<T> {
    
    protected TrieNode<T> root;

    protected long size;

    public TrieImpl() {
        root = new TrieNode<T>();
        root.setKey("");
        size = 0;
    }
quite simply the tree structure is as follows:
 
                               root
                                   |
---------------------------------------------------------------
|                |                      |                      |    (all children are stored in a list)
a               b                     c                     d
|
---------------
|             |
e            f 
also, I have a boolean property for a node which will say if it a leaf node or not.
a leaf node has the property of 'true' and a non-leaf node has a value 'false'

My question is:
I am trying to traverse the tree to output all the words/chars of the tree to test it.
in the above example, the output should be
 ae af b c d 
Can anyone give me some ideas on how to do it?
I am trying to work on it but cant figure out how to end the traversal loop.
It should be recursive traversal tho.

thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 5 2008
Added on Jun 25 2008
15 comments
983 views