Trie data structure implementing addWord

2019-09-16 02:04发布

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 :

enter image description here

Note* the centinel is the last item of the array not the first.

I can't use list I have to use [].

标签: java tree trie
0条回答
登录 后发表回答