问题
I'm stuck with one project, I have to create a "word corrector" and I have to use the "Trie data structure", the thing is that I have to get the words from a file (I know how to do it) but I've implemented this Interface
public interface Trie {
public void add();
public boolean query(String word);
public boolean isEmpty();
}
Then I have a class TreeTrie
which has a inner class Node
public class TreeTrie implements Trie{
private static int cardinalityAlphabet= 0;
private Node node;
private ArbreTrieTau(int cardinality){
this.cardinalityAlphabet= cardinality;
}
private class Node{
Node[] n;
public Node(int num){
//+1 because of centinel
this.n = new Node[num+1];
}
}
Now I'm stuck because I don't know how to start to create the tree, I mean I don't have to build it now, I have to implement the method add, query, isEmpty(), also I think on method add it requires a String word as query method, and then I have to get the charAt(0)
of that word and create a new Node of it?
Do I have to create another method that converts the index 0 to "a", index 1 to "b", etc?
The tree es something like this :
Note* the centinel is the last item of the array not the first.
I can't use list I have to use [].
来源:https://stackoverflow.com/questions/40489404/trie-data-structure-implementing-addword