本文整理汇总了C++中BinaryTree::inOrder方法的典型用法代码示例。如果您正苦于以下问题:C++ BinaryTree::inOrder方法的具体用法?C++ BinaryTree::inOrder怎么用?C++ BinaryTree::inOrder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryTree
的用法示例。
在下文中一共展示了BinaryTree::inOrder方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(){
int foo[8] ={
20, 30, 10, 5, 15, 17, 7, 3
};
BinaryTree bst;
for(int i : foo){
bst.insert(i);
}
bst.printTree(1, 0);
cout<<"In-order print nodes :\n";
bst.inOrder(bst.root);
cout<<endl;
cout<<"Leftmost node of root is: \n";
cout<<leftMostChild(bst.root)->value<<endl;
// test inOrderSuccessor() using every tree node
test(bst);
return 0;
}
示例2: iter
main(int, char **)
{
String cmd;
BinaryTree<String> bt;
while (cmd != 'q')
{
cout << endl;
cout << "quit - q" << endl;
cout << "insert - i" << endl;
cout << "remove - r" << endl;
cout << "clear - c" << endl;
cout << "show - s" << endl;
cout << "copy - C" << endl;
cout << "pre-order - p" << endl;
cout << "post-order - o" << endl;
cout << "in-order - n" << endl;
cout << "level-order - l" << endl;
cout << "choose one: ";
cin >> cmd;
switch (cmd[0])
{
case 'q':
break;
case 'p':
{
cout << endl;
cout << "pre order ... ";
if (bt.preOrder(work) != OK)
cout << "pre order failed !!!" << endl;
cout << endl;
cout << "pre order iterator ... ";
BinaryTreeIterator_PreOrder<String> iter(bt);
for ( ; ! iter.done(); iter++)
{
cout << iter() << " ";
}
cout << endl;
}
break;
case 'o':
{
cout << endl;
cout << "post order ... ";
if (bt.postOrder(work) != OK)
cout << "post order failed !!!" << endl;
cout << endl;
cout << "post order iterator ... ";
BinaryTreeIterator_PostOrder<String> iter(bt);
for ( ; ! iter.done(); iter++)
{
cout << iter() << " ";
}
cout << endl;
}
break;
case 'n':
{
cout << endl;
cout << "in order ... ";
if (bt.inOrder(work) != OK)
cout << "in order failed !!!" << endl;
cout << endl;
cout << "in order iterator ... ";
BinaryTreeIterator_InOrder<String> iter(bt);
for ( ; ! iter.done(); iter++)
{
cout << iter() << " ";
}
cout << endl;
}
break;
case 'l':
{
cout << endl;
cout << "level order ... ";
if (bt.levelOrder(work) != OK)
cout << "level order failed !!!" << endl;
cout << endl;
cout << "level order iterator ... ";
BinaryTreeIterator_LevelOrder<String> iter(bt);
for ( ; ! iter.done(); iter++)
{
cout << iter() << " ";
}
cout << endl;
}
break;
case 'i':
cout << endl;
cout << "character to insert: ";
cin >> cmd;
bt.insert(cmd);
break;
case 'r':
cout << endl;
cout << "character to remove: ";
cin >> cmd;
//.........这里部分代码省略.........