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


C++ Tree::Preorder方法代码示例

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


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

示例1: main

void main()
{
	Tree t;
	int ch=0,x;
	while(ch!=6)
	{
		cout<<"\n\n----Tree----\n";
		cout<<"\n1.Inorder";
		cout<<"\n2.Preorder";
		cout<<"\n3.Postorder";
		cout<<"\n4.Insert";
		cout<<"\n5.Delete";
		cout<<"\n6.Exit";
		cout<<"\nEnter the choice :";
		cin>>ch;
		switch(ch)
		{
		case 1:
			cout<<"\nInorder  : ";
			t.Inorder();
			break;

		case 2:
			cout<<"\nPreorder :";
			t.Preorder();
			break;
		case 3:
			cout<<"\nPostorder:";
			t.Postorder();
			break;
		case 4:
			cout<<"\nEnter the data:";
			cin>>x;
			t.Insert(x);
			break;
		case 5:
			cout<<"\nEnter the data:";
			cin>>x;
			t.Delete(x);
			break;
		}
	}
	
	

}
开发者ID:prijuly2000,项目名称:Data-Structure,代码行数:46,代码来源:main.cpp

示例2: main

int main() {
  Tree* tree = new Tree();                // Create a new tree
  Node* zero;  Node* one; Node* two;      // Declare the Node pointer vars
  Node* three; Node* six; Node* seven;    // Declare the Node pointer vars
  Node* nine;  Node* ten;                 // Declare the Node pointer vars
  
  tree->addRoot(5);                       //  Create the root Node with a value of 5
  Node* root = tree->getRoot();           // Declare the Node pointer vars
  
  nine  = tree->addNode(9, root);
  six   = tree->addNode(6, root);
  ten   = tree->addNode(10,root);
  three = tree->addNode(3, nine);
  two   = tree->addNode(2, nine);
  seven = tree->addNode(7, nine);
  zero  = tree->addNode(0, seven);
  one   = tree->addNode(1, seven);
  
  root->setLeafNode(nine);
  nine->setParentNode(root);
  six->setParentNode(root);
  ten->setParentNode(root);
  
  nine->setSiblingNode(six);
  six->setSiblingNode(ten);
  
  nine->setLeafNode(three);
  three->setParentNode(nine);
  three->setSiblingNode(two);
  two->setSiblingNode(seven);
  
  two->setParentNode(nine);
  seven->setParentNode(nine);
  
  seven->setLeafNode(zero);
  zero->setParentNode(seven);
  zero->setSiblingNode(one);
  one->setParentNode(seven);

  cout << "Pre-Order Traversal\n" << endl;
  tree->Preorder(tree->getRoot());
  
  delete tree;
  return 0;
}
开发者ID:Uben,项目名称:277DataAlg,代码行数:45,代码来源:assignment_8.cpp

示例3: main

// Test main program
int main() {
   Tree* tree = new Tree();
   char data;
   int choice;
   while(1)
   {
      cout<<"1> Add Node\n2> Pre order traversal\n3> In order traversal\n4>Post order traversal\n5> Exit\nCHOOSE WISELY::";
      cin>>choice;
      switch(choice)
      {
        case 1:
        cout<<"\nEnter data:";
        cin>>data;
        tree->addNode(data);
        break;
        case 2:
        cout << "Pre order traversal" << endl;
        tree->Preorder(tree->Root());
        cout << endl;
        break;
        case 3:
        cout << "In order traversal" << endl;
        tree->Inorder(tree->Root());
        cout << endl;
        break;
        case 4:
        cout << "Post order traversal" << endl;
        tree->Postorder(tree->Root());
        cout << endl;
        break;
        case 5:
        exit(0);  



      }
   }
   delete tree;
   return 0;
} 
开发者ID:joyjitc,项目名称:lab,代码行数:41,代码来源:tree.cpp

示例4: main

void main()
{
	Tree t;
	int data,iChoice=0;
	while(iChoice!=5)
	{
		cout<<"\n\t\t1.Insert";
		cout<<"\n\t\t2.Inorder";
		cout<<"\n\t\t3.Preorder";
		cout<<"\n\t\t4.Postorder";
		cout<<"\n\t\t5.Exit";
		cout<<"\nEnter your choice";
		cin>>iChoice;
		switch(iChoice)
		{
		case 1:
				cout<<"\nEnter data to push";
				cin>>data;
				t.Insert(data);
				break;
		case 2:
			t.Inorder();
			break;
		case 3:
			t.Preorder();
			break;
		case 4:
			t.Postorder();
			break;
		case 5:
			break;
		default:
			cout<<"\nInvalid choice";
		}
	}
}
开发者ID:prijuly2000,项目名称:Data-Structure,代码行数:36,代码来源:main.cpp


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