rendered paste bodyclass trietest
{
public static void main(String[] args)
{ Trie trie;
TrieNode rootNode, currentNode, nextNode;
trie = new Trie();
String chars[] = {"t", "a", "c", "c", "a", "g", "t", "a", "c", "c", "a", "g", "t", "a", "c", "c", "a", "c", "t", "a", "#"};
//{"a", "b", "b", "c", "d", "e"};
int i = 0;
boolean addLink = false;
rootNode = trie.head();
currentNode = rootNode;
while(i < chars.length )
{ //System.out.println("Big Loop " + chars[i]);
while(true)
{ //currentNode.printNode("loop");
nextNode = trie.isChild(currentNode, chars[i]);
if(nextNode == null) break; // add chars[i] to currentNode as child
else
{ //nextNode.printNode("Great Success! found " + chars[i]);
currentNode = nextNode;
if( i + 1 < chars.length) i++;
}
}
// so now chars[i] was not found in the current trie, so add it
if(i < chars.length)
{ trie.addNode(currentNode, chars[i]);
System.out.println("(" + currentNode.intvalue + ", " + chars[i] + ")"); // we put the encoding here
currentNode = rootNode;
i++;
}
} // end big while
trie.printTrie();
}// end main
}// end class test