"Behrang" <(EMail Removed)> wrote in message
news:(EMail Removed) ups.com...
 On Oct 1, 4:15 pm, chuck <(EMail Removed)> wrote:
 > 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 herehttp://pastebin.ca/721376
 >
 > and the test file, trietest.java herehttp://pastebin.ca/721378
 >
 > any help is appreciated
 > Chuck

 Hi Chuck,

 You are returning from findNodeIndex too early. I have posted the
 corrected findNodeIndex here:


http://pastebin.ca/721497

 Also, in English, it is spelled "Tree", not "Trie"
There is a data structure called a "trie"
http://en.wikipedia.org/wiki/Trie.
Matt Humphrey
http://www.iviz.com/