本文整理汇总了C++中AvlTree::preOrder方法的典型用法代码示例。如果您正苦于以下问题:C++ AvlTree::preOrder方法的具体用法?C++ AvlTree::preOrder怎么用?C++ AvlTree::preOrder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AvlTree
的用法示例。
在下文中一共展示了AvlTree::preOrder方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(){
AvlTree t;
t.insert(1);
t.insert(2);
t.insert(3);
t.insert(4);
t.insert(5);
preOrder(t.getRoot());
std::cout << std::endl;
t.preOrder();
inOrder(t.getRoot());
std::cout << std::endl;
t.inOrder();
postOrder(t.getRoot());
std::cout << std::endl;
t.postOrder();
std::cout << "Height:" << t.getHeight() << std::endl;
AvlTree t1(t);
std::cout << "t1 Height:" << t1.getHeight() << std::endl;
AvlTree t2;
t2 = t;
std::cout << "t2 Height:" << t2.getHeight() << std::endl;
t.insert(9);
t.inOrder();
t1.inOrder();
t2.inOrder();
return 0;
}
示例2: value
main()
{
AvlTree tree;
Comparable * found = NULL;
Comparable value(10);
vector< Comparable > values;
int i;
int size;
int count;
int preSize;
int inSize;
long inOrder[100];
long toPayam2[100];
long preOrder[100];
for(i=0;i<10;i++) {
Comparable myComp(i);
values.push_back( myComp);
}
// for (i = 0 ; i <10;i++){// NUM_ELEMENTS(TestVals) ; i++) {
// cout << "+++ inserting key #" << i+1<<endl ;//<< ": " << TestVals[i] << endl;
for(i=0;i<10;i++){
found = tree.Insert(&(values[i]));//&TestVals[i]);
if (found)
cout << "\t(already in tree)\n";
}
long * toPayam= tree.bsf(size);
tree.postOrder(count,toPayam2);
tree.preOrder(preSize,preOrder);
tree.inOrder(inSize,inOrder);
cout<<"sldfjsldf"<<endl;
for(i=0;i<inSize;i++) cout<<inOrder[i]<<endl;
//VerifyTree(tree);
// }/* for */
// for (i = 0 ; i < NUM_ELEMENTS(TestVals) ; i++) {
// cout << "+++ searching for key #" << i+1 << ": " << TestVals[i] << endl;
found = tree.Search(1);
if (! found) {
cout << "\t(not found in tree)\n";
}
else cout<<" foung";
/* VerifyTree(tree);
}
for (i = 0 ; i < NUM_ELEMENTS(DelVals) ; i++) {
cout << "+++ deleting key #" << i+1 << ": " << DelVals[i] << endl;
found = tree.Delete(DelVals[i]);
if (! found) {
cout << "\t(not found in tree)\n";
}
VerifyTree(tree);
}
cout << endl << "Deallocating tree ..." << endl;
while (! tree.IsEmpty()) {
found = tree.Delete(0, MAX_CMP);
if (! found) {
cout << "+++ max element not found in tree +++\n";
} else {
cout << "+++ deleted max element " << found->Key() << " +++\n";
}
delete found;
VerifyTree(tree);
}*/
cout << "DONE!" << endl;
cin>>i;
return 0;
}/* main */