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


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

本文整理汇总了C++中BinaryTree::displayInOrder方法的典型用法代码示例。如果您正苦于以下问题:C++ BinaryTree::displayInOrder方法的具体用法?C++ BinaryTree::displayInOrder怎么用?C++ BinaryTree::displayInOrder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BinaryTree的用法示例。


在下文中一共展示了BinaryTree::displayInOrder方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main() {
	cout << "Binary Search Tree" << endl;

	BinaryTree<int> bst;
	cout << "Enter the item into tree (-999)";
	bst.add(45);
	bst.add(60);
	bst.add(80);
	bst.add(77);
	bst.add(75);
	bst.add(70);
	bst.add(48);
	bst.add(40);
	bst.add(32);
	bst.add(35);
	bst.add(30);
	bst.add(50);
	bst.add(53);
	bst.add(57);


	//cin >> item;
//
//	while (item != -999) {
//		bst.add(item);
//		cin >> item;
//	}

	cout << "=== Printing in order" << endl;
	bst.displayInOrder();
//	cout << " == Removing the item If no children " << endl;
//	bst.remove(45);
//	cout << " == Removing the item If no left " << endl;
//	bst.remove(30);
//	bst.displayInOrder();
//	cout << " == Removing the item If no right " << endl;
//	bst.remove(80);
//	bst.displayInOrder();
//	cout << " == Removing the item If has both children " << endl;
//	bst.remove(50);
//	bst.displayInOrder();

	return 0;
}
开发者ID:prepdev,项目名称:Data_bases,代码行数:44,代码来源:BinarySearchTreeTemplate.cpp

示例2: main

int main()
{
   string name;
   
   // Create the binary tree.
   BinaryTree<string> tree;

   // Insert some names.
   for (int count = 0; count < NUM_NODES; count++)
   {
       cout << "Enter an name: ";
       getline(cin, name);
       tree.insertNode(name);
   }
    
   // Display the values.
   cout << "\nHere are the values in the tree:\n";
   tree.displayInOrder();
   return 0;
}
开发者ID:Hongclass,项目名称:C-,代码行数:20,代码来源:Pr20-5.cpp

示例3: manipulateTree

void manipulateTree(BinaryTree<T> tree) // manipulateTree method start
{
	// local variable
	int choice;
	T value;

	do
	{
		choice = submenu(tree.countNodes());
		switch (choice)
		{
		case 1: cout << "\nEnter a value to add: ";
			cin >> value;
			tree.insertNode(value);
			break;
		case 2: cout << "\nEnter a value to remove: ";
			cin >> value;
			try
			{
				tree.remove(value);
			} // end try
			catch (BinaryTree<T>::EmptyNode)
			{
				cout << "\nThe value you entered was not in the tree.\n";
			} // end catch
			break;
		case 3: tree.displayInOrder();
			break;
		case 4: tree.displayPreOrder();
			break;
		case 5: tree.displayPostOrder();
			break;
		case 6: cout << "\nThere are " << tree.countLeaves() << " leaves in the tree.\n";
			break;
		} // end switch
	} while (choice != EXIT);
} // manipulateTree method end
开发者ID:JamesonHuang,项目名称:DataStructor-Algorithm,代码行数:37,代码来源:BinaryTreeTest.cpp

示例4: main

int main()
{
    BinaryTree tree;

    cout << "Inserting nodes...";
    tree.insertNode(5);
    tree.insertNode(8);
    tree.insertNode(3);
    tree.insertNode(12);
    tree.insertNode(9);
    tree.insertNode(21);
    tree.insertNode(1);
    cout << " Done.\n";

    cout << "\n==================================" << endl
    << "           Display                  " << endl
    << "====================================" << endl;

    cout << "Highest to lowest: ";
    tree.displayHiToLow();
    cout << endl;
    /*
    cout << "Inorder:  ";
    tree.displayInOrder() << endl;
    cout << endl << "Postorder:";
    tree.displayPostOrder();
    cout << endl << "Preorder: ";
    tree.displayPreOrder();
    */
    cout << endl;

    cout << "\n==================================" << endl
    << "           Depth Check                 " << endl
    << "====================================" << endl;
    cout << "Depth for 21 = " << tree.depth(21,0) << endl;
    cout << "Depth for 8 = " << tree.depth(8,0) << endl;
    cout << "Depth for 12 = " << tree.depth(12,0) << endl;
    cout << "Depth for 9 = " << tree.depth(9,0) << endl;
    cout << "Depth for 1 = " << tree.depth(1,0) << endl;
    cout << "Depth for 3 = " << tree.depth(3,0) << endl;
    cout << "Depth for 5 = " << tree.depth(5,0) << endl;

    cout << "\n==================================" << endl
    << "           Max Path and Balance            " << endl
    << "====================================" << endl;
    cout << "Sum of max path = " << tree.findMax() << endl;
    cout << "Is the tree balanced...";
    tree.balanceCheck();

    cout << "\n==================================" << endl
    << "           Search and Delete                 " << endl
    << "====================================" << endl;

    tree.displayInOrder();
    cout << "\nSearching for 1...";
    if (tree.searchNode(1) == true)
        cout << "found it.\n";

    cout << "Deleting 1...";
    tree.remove(1);
    cout << "done.\n";

    tree.displayInOrder();
    cout << endl;

    cout << "Searching for 1...";
    if (tree.searchNode(1) == false)
        cout << "couldn't find it.\n";

    return 0;
}
开发者ID:jdvu21,项目名称:Binary-Tree-Iterator,代码行数:71,代码来源:main.cpp


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