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.