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


C++ BinaryTree::inOrder方法代码示例

本文整理汇总了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;
}
开发者ID:ysonggit,项目名称:codelib,代码行数:18,代码来源:4-6-find_next_node.cpp

示例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;
//.........这里部分代码省略.........
开发者ID:ombt,项目名称:ombt,代码行数:101,代码来源:tbinary2.cpp


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