本文整理汇总了C++中TTree::end方法的典型用法代码示例。如果您正苦于以下问题:C++ TTree::end方法的具体用法?C++ TTree::end怎么用?C++ TTree::end使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TTree
的用法示例。
在下文中一共展示了TTree::end方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PrintTree
/*void PrintNode(const TTree<TFoo>::TNode &node, const TTree<TFoo>::TNode* Nil)
{
cout << "Node: " << node.key.Value << endl;
if (node.left != Nil)
cout << "Left: " << node.left -> key.Value << endl;
else cout << "Left: Nil" << endl;
if (node.right != Nil)
cout << "Right: " << node.right -> key.Value << endl;
else cout << "Right: Nil" << endl;
if (node.parent != Nil)
cout << "Parent: " << node.parent -> key.Value << endl;
else cout << "Parent: Nil" << endl;
cout << endl;
}
void PrintTree(const TTree<TFoo>::TNode* node, const TTree<TFoo>::TNode* Nil)
{
if (node != Nil)
{
if (node -> left != 0)
PrintTree(node -> left, Nil);
PrintNode(*node, Nil);
if (node -> right != 0)
PrintTree(node -> right, Nil);
}
}
void Test1()
{
TTree<TFoo> tree;
for (int i = 0; i < 10; ++i)
{
TTree<TFoo>::TNode* node = new TTree<TFoo>::TNode;
node -> key.Value = rand() % 100;
tree.Insert(node);
}
PrintTree(tree.Root, tree.Nil);
while (!tree.IsEmpty())
{
const TTree<TFoo>::TNode* node = tree.Root;
PrintNode(*node, tree.Nil);
tree.Delete(node);
}
}*/
void Test2()
{
srand(time(NULL));
TTree<int> tree;
for (int i = 0; i < 8; ++i)
tree.insert(rand() % 100);
tree.PrintTree();
TTree<int>::iterator iter = tree.begin();
++iter;
tree.erase(iter);
tree.PrintTree();
TTree<int> tree2;
tree2 = tree;
tree2.PrintTree();
tree.clear();
tree.PrintTree();
tree.insert(3);
tree.PrintTree();
tree.swap(tree2);
tree.PrintTree();
tree2.PrintTree();
iter = tree.find(0);
if (iter == tree.end())
cout << "No element" << endl;
else cout << "Element: " << *iter << endl;
TTree<TFoo> tree3;
for (int i = 0; i < 10; ++i)
{
TFoo tmp(i);
tree3.insert(tmp);
}
}
示例2:
static void Test3() {
TTree<TFoo> a;
for (int i = 0; i < 10; ++i)
a.insert(TFoo(i));
TTree<TFoo> b = a;
for (int i = 0; i < 10; ++i)
a.insert(TFoo(i));
TTree<TFoo> c;
a = c;
for (TTree<TFoo>::iterator iter = a.begin(); iter != a.end(); ++iter) {
c.insert(*iter);
}
}