本文整理汇总了C++中AVLTree::Search方法的典型用法代码示例。如果您正苦于以下问题:C++ AVLTree::Search方法的具体用法?C++ AVLTree::Search怎么用?C++ AVLTree::Search使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AVLTree
的用法示例。
在下文中一共展示了AVLTree::Search方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TestAVLTree
void TestAVLTree(int argc, char **argv)
{
int array[TREE_SIZE];
int seed;
bool IsInsert;
if (argc == 2)
seed = atoi(argv[1]);
else
seed = time(0) *257%32768;
SimpleCompareNodesAlgorithm<int, int> CompareAlgorithm;
for (int iteration = 1; iteration <= N_ITERATIONS; iteration++)
{
AVLTree<int, int> *tree;
int i;
printf("Iteration %4d/%4d: seed=%5d", iteration, N_ITERATIONS, seed);
fflush(stdout);
srand(seed++);
for (i = 0; i < TREE_SIZE; i++)
array[i] = i;
Shuffle(array, TREE_SIZE);
tree = new AVLTree<int, int>(&CompareAlgorithm);
for (i = 0; i< TREE_SIZE; i++)
tree->Search(&(array[i]), &IsInsert);
// if (tree->Verify(&IsDone))
// return;
for(i = 0; i < TREE_SIZE; i++)
{
tree->Delete(&(array[i]));
// if (tree->Verify(&IsDone))
// return;
}
printf("\ttest good.\n");
fflush(stdout);
delete tree;
}
}
示例2: main
int main()
{
AVLTree<int> itree;
std::cout << "Insert 0 9 4 6 -4 -2 -1\n";
itree.Insert(0);
itree.Insert(9);
itree.Insert(4);
itree.Insert(6);
itree.Insert(-4);
itree.Insert(-2);
itree.Insert(-1);
std::cout << "InOrder traverse:\n";
itree.InOrderTraverse();
std::cout << "PreOrder traverse:\n";
itree.PreOrderTraverse();
std::cout << "Deleted 9:\n";
itree.Delete(9);
std::cout << "InOrder:\n";
itree.InOrderTraverse();
std::cout << "PreOrder:\n";
itree.PreOrderTraverse();
std::cout << "Deleted 4:\n";
itree.Delete(4);
std::cout << "InOrder:\n";
itree.InOrderTraverse();
std::cout << "PreOrder:\n";
itree.PreOrderTraverse();
std::cout << "Deleted 0:\n";
itree.Delete(0);
std::cout << "InOrder:\n";
itree.InOrderTraverse();
std::cout << "PreOrder:\n";
itree.PreOrderTraverse();
std::cout << "Deleted -2:\n";
itree.Delete(-2);
std::cout << "InOrder:\n";
itree.InOrderTraverse();
std::cout << "PreOrder:\n";
itree.PreOrderTraverse();
std::cout << "Deleted 6:\n";
itree.Delete(6);
std::cout << "InOrder:\n";
itree.InOrderTraverse();
std::cout << "PreOrder:\n";
itree.PreOrderTraverse();
//-----------------------------------------------------------------------------------------
AVLTree<std::string> strTree;
std::cout << "Inserted 5 string: rensehngqiang shibojun lijin wangzaibing zhaogang\n";
strTree.Insert("renshengqiang");
strTree.Insert("shibojun");
strTree.Insert("lijin");
strTree.Insert("wangzaibing");
strTree.Insert("zhaogang");
std::cout << "InOrder traverse:\n";
strTree.InOrderTraverse();
std::cout << "PreOrder traverse:\n";
strTree.PreOrderTraverse();
std::cout << "Look for lijin:\n";
AVLTreeNode<std::string> *pNode = strTree.Search("lijin");
if(pNode != 0) std::cout << pNode->element << std::endl;
std::cout << "Look for huangliangyu\n";
pNode = strTree.Search("huangliangyu");
if(pNode != 0) std::cout << pNode->element << std::endl;
return 0;
}