【发布时间】:2014-10-15 21:57:43
【问题描述】:
我在弄清楚如何找到特里树数据结构的高度时遇到了一些麻烦。我知道对于 AVL 树,一个简单的递归高度函数是:
height(nodeType *node) const
{
if(node == NULL)
return 0;
// if tree is not empty height is 1 + max of either path
return 1 + std::max(height(node->left), height(node->right));
}
但是现在我的 trie 树有一个具有 26 个不同索引的子节点,必须有一种简单的方法来找到最大高度,而无需输入所有 26 个不同的可能索引。我该怎么办?
int height(trieNodeType *node) const
{
if(node == NULL)
return 0;
for(int i = 0; i < 26; i ++) {
//has to be something to do with a for loop,
//i know that much
}
}
【问题讨论】:
-
trieNodeType的定义是什么? -
@cdhowie 它包含一个值,布尔值和
trieNodeType *children[26]