Hi All,
Im trying to implement a trie in java(which is basically a tree used to store words). I have the following method to add a word but am unsure how i would go about check to see if the prefix of a word already exists. Heres my code:
public void add(String word){
for (int i = 0; i<=word.length(); i++){
char c = word.charAt(i);
if(c==..............(trieEdge(c))){ //unsure about this, should check whether an edge with the character c exists in the ith position.
i++;//should go to the next character and node if an edge exists
} else{
word.makeEdge(c);
}
//hereafter I check to see if the end of the word has been reached in wich case the makeNode/edge would place a terminal node at the end rather than a normal node.
If anyone can give me suggestions as to how I can check to see if the edge already exists in correspondance to the ith position this will be very much appreciated
Cheers