当前位置: 首页>>代码示例>>C++>>正文


C++ Tree::Clear方法代码示例

本文整理汇总了C++中Tree::Clear方法的典型用法代码示例。如果您正苦于以下问题:C++ Tree::Clear方法的具体用法?C++ Tree::Clear怎么用?C++ Tree::Clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tree的用法示例。


在下文中一共展示了Tree::Clear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: menu

void  menu()
{
	Tree *tree = new Tree;
	char c;
	do
	{
		printf("1: View\n");
		printf("2: Find\n");
		printf("3: Add\n");
		printf("4: Del\n");
		printf("5: Clear\n");
		printf("\nEsc: Exit\n");
		c = getch();
		switch(c)
		{
		case '1': 
			cout << "Print:";
			tree->Print();
			cout << endl; break;
		case '2': 
			cout << "Find:";
			int val;
			cin >> val;
			bool flag;
			flag = tree->Exists(val); 
			cout << (flag == true ? "true" : "false") << endl; break;
		case '3': 
			cout << "Add:";
			int add;
			cin >> add;
			tree->Add(add); cout << endl; break;
		case '4': 
			cout << "Delete:";
			int del;
			cin >> del;
			tree->Delete(del); cout << endl; break;
		case '5': tree->Clear();  cout << endl; break;
		}
	} while(c != 27);
	delete tree;
}
开发者ID:klyuchnikov,项目名称:LabsThreeSemestrsEVM,代码行数:41,代码来源:Main.cpp

示例2: main

int main(int argc, char *argv[])
{
    Tree<int, int> tree;
    unsigned int num, key, key2, root;
    bool error;


    srand(time(NULL));

    build_tree(&tree, 0, 20);

    key = rand_int(0, 20);
    key2 = rand_int(0, 20);
    num = tree.SearchByKey(key2, &error);

    print_valid(&tree);

    cout << endl << "[Remove by key " << key << "]" << endl;

    if (tree.RemoveByKey(key))
    {
        cout << "ERROR removing by key " << key << endl;
    }

    print_valid(&tree);

    ////////////////////////////////////////////////////////////////

    cout << endl << "[Remove ( key " << key2 << ") by data " << num << "]"
         << endl;

    if (tree.RemoveByData(num))
    {
        cout << "ERROR removing by data " << num << endl;
    }

    print_valid(&tree);

    ////////////////////////////////////////////////////////////////

    root = tree.Root();
    cout << endl << "[Remove root " << root << " by key " << root << "]" << endl;

    if (tree.RemoveByKey(root))
    {
        cout << "ERROR removing by key " << root << endl;
    }

    print_valid(&tree);

    ////////////////////////////////////////////////////////////////

    cout << endl << "[Insert]" << endl;
    build_tree(&tree, 20, 23);

    print_valid(&tree);

    ////////////////////////////////////////////////////////////////

    root = tree.Root();
    cout << endl << "[Remove root " << root << " by key " << root << "]" << endl;

    if (tree.RemoveByKey(root))
    {
        cout << "ERROR removing by key " << root << endl;
    }

    print_valid(&tree);

    ////////////////////////////////////////////////////////////////

    cout << endl << "[Clear tree]" << endl;
    tree.Clear();

    print_valid(&tree);

    ////////////////////////////////////////////////////////////////

    cout << endl << "[Build new tree]" << endl;
    build_tree(&tree, 0, 5);

    print_valid(&tree);

    return 0;
}
开发者ID:OldRepoPreservation,项目名称:freyja,代码行数:85,代码来源:Tree.cpp


注:本文中的Tree::Clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。