コード例 #1
0
ファイル: rbt.cpp プロジェクト: divyang4481/mipt-hw
/*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
0
ファイル: rbt.cpp プロジェクト: divyang4481/mipt-hw
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);
    }
}