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


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

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


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

示例1: main

int main(int argc, char *argv[]){
    Tree<int> Apple;

    Apple.Insert(8);
	Apple.Insert(10);
	Apple.Insert(4);
	Apple.Insert(2);
	Apple.Insert(6);
	Apple.Insert(5);
	
	// Apple.Remove(5);
	// Apple.Remove(4);

    
    cout << "PRE-ORDER:" << endl;
    Apple.TraversePreOrder(Apple.Root());
	cout << endl << endl;
	
	cout << "POS-ORDER:" << endl;
	Apple.TraversePosOrder(Apple.Root());
	cout << endl << endl;
		
	cout << "IN-ORDER:" << endl;
	Apple.TraverseInOrder(Apple.Root());
	cout << endl << endl;
	
	cout << "LEVEL-ORDER:" << endl;
	Apple.TraverseLevelOrder();
	cout << endl << endl;
	
    return 0;
}
开发者ID:MilkLin,项目名称:AVL-Tree,代码行数:32,代码来源:AVL+Tree.cpp

示例2: main

int main()
{
	Tree tree;
	RandGen rg;

	int i = 0;
	while (i < 100)
	{
		if (tree.Insert(rg(100) - 50))
		{
			++i; //Need a tree Transversal (display) "pre order" "post order"
		}
	}

	//TRANSVERSAL OUTPUTS  ******ROOT IS BEGGINING OF PRE AND END OF POST*********
	tree.InOrder(std::cout);
	std::cout << std::endl;
	std::cout << std::endl;
	tree.PreOrder(std::cout);
	std::cout << std::endl;
	std::cout << std::endl;
	tree.PostOrder(std::cout);
	std::cout << std::endl;
	std::cout << std::endl;

	system("pause");
	return 0;
}
开发者ID:JustinMorritt,项目名称:C-,代码行数:28,代码来源:Main.cpp

示例3: main

int main(){
	Tree mTree;
	mTree.setHead();
	mTree.CreateTree(mTree.head,32);			//expected height of the tree	is 33.
	int Q; 
	string s;
	int num;
	for(int i=0;i<Q;i++){
		cin>>s;
		cin>>num;
		switch (s[0]){
		case 'a':		//add
			mTree.Insert(num);			
			break;
		case 'd':		//delete
			mTree.Delete(num);
			break;
		case 'c':		//count
			mTree.TotalCount=0;
			mTree.GetCount(mTree.head,num);
			cout<<mTree.TotalCount<<endl;			
			break;
		}
	}


	return 0;
}
开发者ID:AbhishekTiwari0812,项目名称:hackerrank_problems,代码行数:28,代码来源:counter_code6.cpp

示例4: countRangeSum

    int countRangeSum(vector<int>& nums, int lower, int upper) {
        Tree tree;
        tree.Insert(0);
        long long sum = 0;
        int res = 0;

        for (int n : nums) {
            sum += n;
            int lcnt = tree.LessThan(sum, lower);
            int hcnt = tree.LessThan(sum, upper + 1);
            res += (hcnt - lcnt);
            tree.Insert(sum);
        }

        return res;
    }
开发者ID:xegg,项目名称:JustSomeLearningNoteAndScript,代码行数:16,代码来源:count_of_range_sum.cpp

示例5: 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

示例6: main

int main()
{
	Tree obj;
	obj.Insert(8);
	obj.Insert(3);
	obj.Insert(1);
	obj.Insert(10);
	obj.Insert(6);
	obj.Insert(4);
	obj.Insert(7);
	obj.Insert(14);
	obj.Insert(13);
	obj.PostorderTraversal();
	cout << endl;
	cout << obj.TreePermutationCount(2);
	//cout << endl << obj.InternalPath();
	return 0;
}
开发者ID:andriy-kuz,项目名称:Algorithms,代码行数:18,代码来源:BinarySearchTree.cpp

示例7: 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

示例8: main

int main()
{
   Tree myTree;

 	bool inMenu = true;	// while the user is using the program this var is set to true and the menu keeps looping.
						// when the user wants to quit, it is set to false and the loop ends.
	char keyPressed;	// This var stores which menu selection the user picks.

	while ( inMenu )
	{
		cout<< endl << endl << endl;
		cout << "****************************************************" << endl;
		cout  <<"**  MENU:(press a character to select an option)  **" << endl;
 		cout << "****************************************************" << endl;
		cout<<"Q. [QUIT]     Quit."<<endl;
  		cout<<"D. [Display]  Display all values stored in the tree"<<endl;
 		cout<<"I. [Insert]   Insert an integer"<<endl;
		cout << endl;

		cout<<"M. [Maximum] Determine the maximum of all values stored in the tree" << endl;
		cout<<"A. [Average] Determine the average of all values stored in the tree" << endl;
		cout<<"H. [Height]  Determine the height of the tree" << endl;
		cout << "****************************************************" <<endl<< endl;

		cout<<"Your choice is: ";
		cin >> keyPressed ;

		int value;
		switch(keyPressed)
		{
			case 'M': case 'm'://Maximum
				cout << "[Maximum]:" << endl;
				cout << "Maximum value stored is:" << myTree.FindMaximum() << endl;
				break;

			case 'A': case 'a'://Average
				cout << "[Average]:" << endl;
				cout << "Average of all values stored is:" << myTree.FindAverage() << endl;
				break;

			case 'H': case 'h'://height
				cout << "[Height]:" << endl;
				cout << "Height of the tree is:" << myTree.FindHeight()<< endl;
				break;


			case 'Q': case 'q'://Quit
				cout << "[QUIT]:" << endl;
				inMenu = false;
				break;

			case 'D': case 'd':
				cout << "[Display]:" << endl;
				myTree.Display();
				break;

			case 'I': case 'i':
				cout << "[insert]:" << endl;
				cout << "Value to insert:";
				cin >> value;
				myTree.Insert(value);
				break;

			default:
				cout << "[?? UNKNOWN COMMAND]:" << endl;
				// Unrecognized key, do nothing
				break;
		}


	} // End of while loop

	return 0;
}
开发者ID:RoyalSix,项目名称:binarysearchtree,代码行数:74,代码来源:main.cpp

示例9: REQUIRE

#include <tree.cpp>
#include <catch.hpp>
#include <fstream>
#include <iostream>
using namespace std;

SCENARIO("Insert_int", "[add]"){
  Tree<int> tree;
  REQUIRE(tree.Insert(7));
  REQUIRE(tree.Insert(3));
  REQUIRE(tree.Insert(5));
  REQUIRE(tree.Search(3));
  REQUIRE(tree.Search(5));
  REQUIRE(tree.Search(7));
}

SCENARIO("Insert_char", "[add_c]"){
  Tree<char> tree;
  REQUIRE(tree.Insert(5));
  REQUIRE(tree.Insert(4));
  REQUIRE(tree.Insert(6));
  REQUIRE(tree.Search(4));
  REQUIRE(tree.Search(5));
  REQUIRE(tree.Search(6));
}

SCENARIO("Insert_double", "[add_d]"){
  Tree<double> tree;
  REQUIRE(tree.Insert(7.62));
  REQUIRE(tree.Insert(3.14));
  REQUIRE(tree.Insert(5.85));
开发者ID:Balanar300hp,项目名称:Tree,代码行数:31,代码来源:init.cpp


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