tree.hh: an STL-like C++ tree classを使用してツリーを作成し、下のツリーを取得するにはどうすればよいですか?いくつかの助けに感謝するでしょう。 AおよびG iがリスト内の項目をenumarateする深さ優先検索を使用している、上記その後のコードで 感謝のtree.hh STLを使用してn-aryツリーを作成する
A G
______|____ |
/ | \ |
B C D H
| | | |
| E | |
\_____/ | |
| | |
F | |
|_________|______|
|
I
|
J
ルートノードです。私はこの
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 graph](http://www.boost.org/libs/graph/)の使用を検討することもできます。 – user2k5
リプレイのために、私はまずツリーを作成したい、それが必要な場合は、グラフを使用します。 – htk59
私は混乱しています。 [ツリー](http://en.wikipedia.org/wiki/Tree_(data_structure))では、各ノードに親が1つしかありません。しかし、あなたの 'A'ノードには3つあるようです。 –