C
chuck
Hello,
I wrote a simple Trie class that creates a Trie structure correctly
from character array. It will correctly recurisivley print the trie
correctly too, albeit not sorted.
The trie structue is a linked lists structure. Each node has two
pointers, next(sibling) and link(children).
I adapted the same structure that my print trie method uses to search
the trie for a particular integer index and want to return the trie
node if the index is found. The search seems to stop the recursion
when it finds the node, but returns null. The only node it correctly
find is the root.
public TrieNode findNodeIndex(TrieNode currentNode, int i){
// if(currentNode.index == i) return currentNode;
if(currentNode.link != null) findNodeIndex(currentNode.link, i);
//System.out.println( currentNode);
if(currentNode.index == i) return currentNode;
if(currentNode.next != null) findNodeIndex(currentNode.next, i);
//if(currentNode.index == i) return currentNode;
return null;
}
I have tried putting the test in various places without success, any
ideas why this fails?
If it helps i put Trie.java here
http://pastebin.ca/721376
and the test file, trietest.java here
http://pastebin.ca/721378
any help is appreciated
Chuck
I wrote a simple Trie class that creates a Trie structure correctly
from character array. It will correctly recurisivley print the trie
correctly too, albeit not sorted.
The trie structue is a linked lists structure. Each node has two
pointers, next(sibling) and link(children).
I adapted the same structure that my print trie method uses to search
the trie for a particular integer index and want to return the trie
node if the index is found. The search seems to stop the recursion
when it finds the node, but returns null. The only node it correctly
find is the root.
public TrieNode findNodeIndex(TrieNode currentNode, int i){
// if(currentNode.index == i) return currentNode;
if(currentNode.link != null) findNodeIndex(currentNode.link, i);
//System.out.println( currentNode);
if(currentNode.index == i) return currentNode;
if(currentNode.next != null) findNodeIndex(currentNode.next, i);
//if(currentNode.index == i) return currentNode;
return null;
}
I have tried putting the test in various places without success, any
ideas why this fails?
If it helps i put Trie.java here
http://pastebin.ca/721376
and the test file, trietest.java here
http://pastebin.ca/721378
any help is appreciated
Chuck