Trie data structure implementing addWord

时光总嘲笑我的痴心妄想 提交于 2019-12-25 04:38:13

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!