本文整理汇总了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;
}
示例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;
}