我如何使用tree.hh: an STL-like C++ tree class填充我的树并获取下面的树。一些帮助将不胜感激。 a和g是根节点 谢的使用tree.hh填充n-tree tree STL Like
A G
______|____ |
/ | \ |
B C D H
| | | |
| E | |
\_____/ | |
| | |
F | |
|_________|______|
|
I
|
J
在然后上面的代码中,我使用深度优先搜索列表中的项目enumarate。我已经格式化这样
typedef tree<std::string> TreeNode;
typedef struct
{
int nBases;
char * name;
} BASES;
BASES rgbases[] =
{
{0xB, "J"},
{0xA, "I"},
{0x1, "H"},{0x0, "G"},
{0x5, "F"},{0x2, "E"},{0x1, "C"},{0x0, "A"},
{0x1, "D"},{0x0, "A"},
{0x1, "B"},{0x0, "A"}
};
//here i'm trying to populate my tree
void populateTree(TreeNode &tr, BASES *pBaseArray, int numBase)
{
int n = 0;
while (n < numBase)
{
BASES *pBase = &pBaseArray[n];
if (pBase->nBases > 0) // Check for children of the new node
populateTree(tr, pBaseArray + (n + 1),pBase->nBases);
// i suppose i need to insert tree code part here
n += pBase->nBases + 1;
}
}
void BuildTree(TreeNode &tr)
{
populateTree(tr, rgBases, _countof(rgBases));
}
据我所知,tree.hh不能给你图。你可以考虑使用[boost图表](http://www.boost.org/libs/graph/)。 – user2k5
感谢您的回复,我希望先创建我的树,如果有必要,我可以使用图表。 – htk59
我很困惑。在[tree](http://en.wikipedia.org/wiki/Tree_(data_structure))中,每个节点最多只有一个父节点。但是你的'A'节点似乎有三个。 –