【发布时间】:2012-10-28 21:25:33
【问题描述】:
我正在实现一个 trie,它将同时存储子字符串及其在字符串中的出现次数。我的 trie 中的每个节点都会有一个名为 children 的 Map,它将存储主节点的所有子节点。
我的问题是,最终,这些子节点将拥有自己的子节点,我不知道如何从“地图中的地图中的地图......”可以这么说。
这是我目前所拥有的:
private class TrieNode
{
private T data; //will hold the substring
int count; //how many occurrences of it were in the string
private Map<TrieNode, Integer> children; //will hold subnodes
private boolean isWord; //marks the end of a word if a substring is the last substring of a String
private TrieNode(T data)
{
this.data = data;
count = 1;
children = new HashMap<TrieNode, Integer>();
isWord = false;
}
}
如何从子节点中检索数据,这些子节点下可能有其他子节点?
附:如果我无法足够清楚地解释它,我深表歉意 - 我遇到了递归问题。谢谢。
【问题讨论】:
标签: java string recursion trie