本文整理汇总了C++中TTree::AddNode方法的典型用法代码示例。如果您正苦于以下问题:C++ TTree::AddNode方法的具体用法?C++ TTree::AddNode怎么用?C++ TTree::AddNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TTree
的用法示例。
在下文中一共展示了TTree::AddNode方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: s_TEST_Tree
static void s_TEST_Tree()
{
typedef CTreeNode<int> TTree;
TTree* tr = new TTree(0);
TTree* tr10 = tr->AddNode(10);
tr->AddNode(11);
tr10->AddNode(20);
tr10->AddNode(21);
TTree* sr = new TTree(0);
sr->AddNode(10);
sr->AddNode(11);
delete sr;
sr = 0;
TTree* ur = new TTree(0);
ur->AddNode(10);
ur->AddNode(11);
ur->AddNode(20);
ur->AddNode(21);
delete ur;
ur = 0;
// TreePrint(cout, *tr, (IntConvType) NStr::IntToString);
// TreeReRoot(*tr10);
// TreePrint(cout, *tr10, (IntConvType) NStr::IntToString);
cout << "Testing Breadth First Traversal" << endl;
TreeBreadthFirstTraverse(*tr, TestFunctor2);
cout << endl;
cout << "Testing Depth First Traversal" << endl;
TreeDepthFirstTraverse(*tr, TestFunctor1);
cout << endl;
{{
unsigned int cnt;
TTree::TNodeList_CI it = tr->SubNodeBegin();
TTree::TNodeList_CI it_end = tr->SubNodeEnd();
for (cnt = 0; it != it_end; ++it, ++cnt) {
const TTree* t = *it;
int v = t->GetValue();
assert(v == 10 || v == 11);
}
assert(cnt == 2);
}}
{{
TTree* tr2 = new TTree(*tr);
unsigned int cnt;
TTree::TNodeList_CI it = tr2->SubNodeBegin();
TTree::TNodeList_CI it_end = tr2->SubNodeEnd();
for (cnt = 0; it != it_end; ++it, ++cnt) {
const TTree* t = *it;
int v = t->GetValue();
assert(v == 10 || v == 11);
}
assert(cnt == 2);
delete tr2;
}}
{{
TTree::TNodeList_I it = tr->SubNodeBegin();
TTree::TNodeList_I it_end = tr->SubNodeEnd();
for (; it != it_end; ++it) {
TTree* t = *it;
int v = t->GetValue();
if (v == 10)
{
tr->RemoveNode(t);
break;
}
}
}}
TreeDepthFirstTraverse(*tr, TestFunctor1);
cout << endl;
{{
unsigned int cnt;
TTree::TNodeList_CI it = tr->SubNodeBegin();
TTree::TNodeList_CI it_end = tr->SubNodeEnd();
for (cnt = 0; it != it_end; ++it, ++cnt) {
const TTree* t = *it;
int v = t->GetValue();
assert(v == 11);
}
assert(cnt == 1);
}}
delete tr;
TTree* str = tr = new TTree(0);
//.........这里部分代码省略.........
示例2: s_TEST_TreeOperations
static void s_TEST_TreeOperations()
{
typedef CTreeNode<int> TTree;
TTree* orig = new TTree(0);
TTree* orig10 = orig->AddNode(10);
TTree* orig11 = orig->AddNode(11);
orig10->AddNode(20);
orig10->AddNode(21);
orig11->AddNode(22);
orig11->AddNode(23);
TTree* corr = new TTree(11);
corr->AddNode(22);
corr->AddNode(23);
TTree* corr0 = corr->AddNode(0);
TTree* corr10 = corr0->AddNode(10);
corr10->AddNode(20);
corr10->AddNode(21);
TreeReRoot(*orig10);
cout << "After rerooting original tree by node 10, " << endl;
cout << "the original tree and correct tree are now ";
if(TreeCompare(*orig10, *corr, TestFunctor3)) {
cout << "the same." << endl;
}
else {
cout << "different." << endl;
}
cout << endl;
TreePrint(cout, *orig10, s_IntToStr, false);
TreePrint(cout, *corr, s_IntToStr, false);
cout << endl;
/*
TTree* corr2 = new TTree(11);
corr2->AddNode(22);
corr2->AddNode(23);
corr2->AddNode(0);
TTree* t = orig->DetachNode(orig10);
cout << "After removing node 10 from this tree, " << endl;
cout << "the original tree and correct tree are now ";
if(TreeCompare(*orig11, *corr2, TestFunctor3)) {
cout << "the same." << endl;
}
else {
cout << "different." << endl;
}
cout << endl;
TreePrint(cout, *orig11, s_IntToStr, false);
TreePrint(cout, *t, s_IntToStr, false);
TreePrint(cout, *corr2, s_IntToStr, false);
cout << endl;
*/
delete orig->GetRoot();
delete corr->GetRoot();
}
示例3: s_TEST_IdTreeOperations
static void s_TEST_IdTreeOperations()
{
cout << "--------------------- s_TEST_IdTreeOperations " << endl;
typedef CTreeNode<IdValue> TTree;
TTree* tr = new TTree(0);
TTree* tr10 = tr->AddNode(10);
TTree* tr11 = tr->AddNode(11);
TTree* tr110 = tr10->AddNode(110);
TTree* tr1100 = tr110->AddNode(1100);
TreePrint(cout, *tr, s_IdValueToStr);
bm::bvector<> bv;
TreeMakeSubNodesSet(*tr, bv.inserter());
assert(bv.count() == 2);
assert(bv[10]);
assert(bv[11]);
typedef vector<TTree*> TNodeList;
TNodeList node_list;
node_list.push_back(tr10);
node_list.push_back(tr11);
node_list.push_back(tr110);
node_list.push_back(tr1100);
TNodeList res_node_list;
CTreeNonRedundantSet<TTree, bm::bvector<>, TNodeList> nr_func;
nr_func(node_list, res_node_list);
cout << "Non-redundant set:" << endl;
ITERATE(TNodeList, it, res_node_list) {
cout << (*it)->GetValue().GetId() << "; ";
}
cout << endl;
assert(res_node_list.size() == 2);
res_node_list.clear();
node_list.clear();
node_list.push_back(tr110);
node_list.push_back(tr1100);
CTreeMinimalSet<TTree, bm::bvector<>, TNodeList> min_func;
min_func(node_list, res_node_list);
cout << "Minimal set:" << endl;
ITERATE(TNodeList, it, res_node_list) {
cout << (*it)->GetValue().GetId() << "; ";
}
cout << endl;
cout << "-----" << endl;
assert(res_node_list.size() == 1);
res_node_list.clear();
node_list.clear();
node_list.push_back(tr110);
node_list.push_back(tr1100);
node_list.push_back(tr11);
min_func(node_list, res_node_list);
cout << "Minimal set:" << endl;
ITERATE(TNodeList, it, res_node_list) {
cout << (*it)->GetValue().GetId() << "; ";
}
cout << endl;
cout << "-----" << endl;
assert(res_node_list.size() == 1);
res_node_list.clear();
node_list.clear();
TNodeList node_list_a;
TNodeList node_list_b;
TNodeList node_list_c;
node_list_a.push_back(tr10);
node_list_a.push_back(tr11);
node_list_a.push_back(tr110);
node_list_a.push_back(tr1100);
node_list_b.push_back(tr10);
node_list_b.push_back(tr11);
node_list_b.push_back(tr110);
CTreeNodesAnd<TTree, bm::bvector<>, TNodeList> and_func;
and_func(node_list_a, node_list_b, node_list_c);
//.........这里部分代码省略.........
示例4: s_TEST_IdTree
static void s_TEST_IdTree()
{
typedef CTreePair<int, int>::TTreePair TTreePair;
typedef CTreePair<int, int>::TPairTreeNode TTree;
TTree* tr = new TTree(TTreePair(0, 0));
tr->AddNode(TTreePair(1, 10));
tr->AddNode(TTreePair(100, 110));
TTree* tr2 = tr->AddNode(TTreePair(2, 20));
tr2->AddNode(TTreePair(20, 21));
TTree* tr3 =tr2->AddNode(TTreePair(22, 22));
tr3->AddNode(TTreePair(222, 222));
{{
const TTree* tnd = tr->FindSubNode(100);
assert(tnd);
assert(tnd->GetValue().id == 100);
assert(tnd->GetValue().value == 110);
const TTree& tv = tnd->GetValue();
assert(tv.GetValue().value == 110);
}}
{{
list<int> npath;
npath.push_back(2);
npath.push_back(22);
TTree::TConstNodeList res;
tr->FindNodes(npath, &res);
assert(!res.empty());
TTree::TConstNodeList::const_iterator it = res.begin();
const TTree* ftr = *it;
assert(ftr->GetValue().value == 22);
}}
{{
list<int> npath;
npath.push_back(2);
npath.push_back(32);
TTree::TConstNodeList res;
tr->FindNodes(npath, &res);
assert(res.empty());
}}
{{
list<int> npath;
npath.push_back(2);
npath.push_back(22);
npath.push_back(222);
npath.push_back(100);
const TTree* node = PairTreeTraceNode(*tr, npath);
assert(node);
cout << node->GetValue().id << " " << node->GetValue().value << endl;
assert(node->GetValue().value == 110);
node = PairTreeBackTraceNode(*tr3, 1);
assert(node);
cout << node->GetValue().id << " " << node->GetValue().value << endl;
assert(node->GetValue().value == 10);
}}
{{
list<int> npath;
npath.push_back(2);
npath.push_back(22);
npath.push_back(222);
const TTree* node = PairTreeTraceNode(*tr, npath);
assert(node);
cout << node->GetValue().id << " " << node->GetValue().value << endl;
assert(node->GetValue().value == 222);
}}
delete tr;
}
示例5: s_TEST_Tree
static void s_TEST_Tree()
{
typedef CTreeNode<int> TTree;
TTree* tr = new TTree(0);
TTree* tr10 = tr->AddNode(10);
tr->AddNode(11);
tr10->AddNode(20);
tr10->AddNode(21);
TTree* sr = new TTree(0);
sr->AddNode(10);
sr->AddNode(11);
TTree* ur = new TTree(0);
ur->AddNode(10);
ur->AddNode(11);
ur->AddNode(20);
ur->AddNode(21);
// TreePrint(cout, *tr, (IntConvType) NStr::IntToString);
// TreeReRoot(*tr10);
// TreePrint(cout, *tr10, (IntConvType) NStr::IntToString);
cout << "Testing Breadth First Traversal" << endl;
TreeBreadthFirstTraverse(*tr, TestFunctor2);
cout << endl;
cout << "Testing Depth First Traversal" << endl;
TreeDepthFirstTraverse(*tr, TestFunctor1);
cout << endl;
cout << "Testing Tree Comparison" << endl;
cout << "tr and tr10 are ";
if(!TreeCompare(*tr, *tr10, TestFunctor3)) cout << "not ";
cout << "the same." << endl;
cout << "tr and tr are ";
if(!TreeCompare(*tr, *tr, TestFunctor3)) cout << "not ";
cout << "the same." << endl;
cout << "tr and sr are ";
if(!TreeCompare(*tr, *sr, TestFunctor3)) cout << "not ";
cout << "the same." << endl;
cout << "tr and ur are ";
if(!TreeCompare(*tr, *ur, TestFunctor3)) cout << "not ";
cout << "the same." << endl;
cout << "sr and ur are ";
if(!TreeCompare(*sr, *ur, TestFunctor3)) cout << "not ";
cout << "the same." << endl;
cout << endl;
{{
unsigned int cnt;
TTree::TNodeList_CI it = tr->SubNodeBegin();
TTree::TNodeList_CI it_end = tr->SubNodeEnd();
for (cnt = 0; it != it_end; ++it, ++cnt) {
const TTree* t = *it;
int v = t->GetValue();
assert(v == 10 || v == 11);
}
assert(cnt == 2);
}}
{{
TTree* tr2 = new TTree(*tr);
unsigned int cnt;
TTree::TNodeList_CI it = tr2->SubNodeBegin();
TTree::TNodeList_CI it_end = tr2->SubNodeEnd();
for (cnt = 0; it != it_end; ++it, ++cnt) {
const TTree* t = *it;
int v = t->GetValue();
assert(v == 10 || v == 11);
}
assert(cnt == 2);
delete tr2;
}}
{{
TTree::TNodeList_I it = tr->SubNodeBegin();
TTree::TNodeList_I it_end = tr->SubNodeEnd();
for (; it != it_end; ++it) {
TTree* t = *it;
int v = t->GetValue();
if (v == 10)
{
tr->RemoveNode(t);
break;
}
}
}}
TreeDepthFirstTraverse(*tr, TestFunctor1);
cout << endl;
{{
unsigned int cnt;
//.........这里部分代码省略.........