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


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

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


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

示例1: main

int main()
{
	BinaryTree tree;
	vector<double> treeValues;

	tree.insert(5.2);
	tree.insert(8.6);
	tree.insert(3.1);
	tree.insert(12.9);
	tree.insert(9.7);

	if (tree.search(3))
		cout << "3 was found in tree.\n";
	else
		cout << "3 was not found in tree.\n";

	tree.inorder(treeValues);

	for (int i = 0; i < treeValues.size(); i++)
	{
		cout << treeValues[i] << "  ";
	}
	cout << endl;

	return 0;
}
开发者ID:Jgro1234,项目名称:StartingOutCPP,代码行数:26,代码来源:PC_19_1.cpp

示例2: main

int main(){

	char anyKey;
	cout<<"Arboles Binarios"<<endl;

	BinaryTree<TreeTraits> btMyTree;
	
	btMyTree.insert(33);
	btMyTree.insert(23);
	btMyTree.insert(41);
	btMyTree.insert(11);
	btMyTree.insert(27);
	btMyTree.insert(37);
	btMyTree.insert(51);
	
	cout<<"InOrder"<<endl;
	btMyTree.in_order(btMyTree.root);
	cout<<"PreOrder"<<endl;
	btMyTree.pre_order(btMyTree.root);
	cout<<"PostOrder"<<endl;
	btMyTree.post_order(btMyTree.root);

	cout<<"Wait any key ..."<<endl;
	cin>>anyKey;
	return 0;
};
开发者ID:dorisserruto,项目名称:cplus2basic,代码行数:26,代码来源:main.cpp

示例3: BT_depth_first

void BT_depth_first()
{
    BinaryTree<int> T;

    T.insert(5);
    T.insert(104);
    T.insert(2);
    T.insert(3);
    T.insert(10);
    T.insert(130);
    T.insert(60);
    T.insert(9);
    T.insert(78);
    T.insert(11);
    T.insert(8);

    cout << "BinaryTree inorder traverse" << endl;
    T.inorder();

    /* You see the depth-first traverse result
     * is ordered
     */
    cout << "BinaryTree depth-first traverse" << endl;
    T.depth_first();
}
开发者ID:wizarddewhite,项目名称:data-structures,代码行数:25,代码来源:BinaryTree.cpp

示例4: main

int main()
{
	BinaryTree comp;
	string result;
	int input;

	comp.insert(1021, "John Williams");
	comp.insert(1057, "Bill Witherspoon");
	comp.insert(2487, "Jennifer Twain");
	comp.insert(3769, "Sophia Lancaster");
	comp.insert(1017, "Debbie Reece");
	comp.insert(1275, "George McMullen");
	comp.insert(1899, "Ashley Smith");
	comp.insert(4218, "Josh Plemmons");

	do 
	{
		cout << "\nEnter an Employee ID Number\n";
		cout << "or enter -1 to exit program: ";
		cin >> input;

		if (input != -1)
		{
			result = comp.search(input);
			if (result == "Error")
				cout << result << ": Employee ID not found.\n";
			else
				cout << "Employee name: " <<result << endl;
		}

	} while (input != -1);
	return 0;
}
开发者ID:Jgro1234,项目名称:StartingOutCPP,代码行数:33,代码来源:PC_19_8.cpp

示例5: main

int main(){
	BinaryTreeNode b = BinaryTreeNode(12);
	std::cout << b.get_value() << std::endl;

	BinaryTreeNode *pb = new BinaryTreeNode(13);
	std::cout << pb->get_value() << std::endl;

	BinaryTree t = BinaryTree(50);
	t.insert(30);
	t.insert(20);
	t.insert(40);
	t.insert(80);
	t.insert(70);
	t.insert(90);
	t.insert(60);
	t.insert(100);
	t.insert(85);
	t.insert(101);
	t.insert(102);
	t.insert(103);
	t.insert(105);

	std::cout << "DEBUG" << std::endl;
	t.remove(30);
	t.remove(20);
	
	
	

	return 0;
	
}
开发者ID:Panaetius,项目名称:FHNW-Java-Projekte,代码行数:32,代码来源:BinaryTree.cpp

示例6: main

int main() {
 
    BinaryTree<int> tree;
    tree.insert(13);
    tree.insert(10);
    tree.insert(25);
    tree.insert(2);
    tree.insert(12);
    tree.insert(20);
    tree.insert(31);
    tree.insert(29);

    //tree.morrisInOrder();
    //cout << endl;
    
    BSTNode<int>* root = new BSTNode<int>(13);
    root->parent = 0;

    root->left = new BSTNode<int>(10);
    root->left->parent = root;

    root->right = new BSTNode<int>(25);
    root->right->parent = root;

    root->left->left = new BSTNode<int>(2);
    root->left->left->parent = root->left;

    root->left->right = new BSTNode<int>(12);
    root->left->right->parent = root->left;

    root->right->left = new BSTNode<int>(20);
    root->right->left->parent = root->right;

    root->right->right = new BSTNode<int>(31);
    root->right->right->parent = root->right;
    
    root->right->right->left = new BSTNode<int>(29);
    root->right->right->left->parent = root->right->right;
    
    BinaryTree<int> tree2(root);
    
    tree2.morrisInOrder();
    cout << endl;
    traverse<int>(root);
    cout << endl;

    //traverse<int>(root);

    return 0;
}
开发者ID:B-Rich,项目名称:Elements_Of_Programming_Interview,代码行数:50,代码来源:epi9_5.cpp

示例7: insert

 void insert(int val){
   if(val<=value){
     if(left == NULL){
       left = new BinaryTree(val);
       return;
     }
     left->insert(val);
   }else{
     if(right == NULL){
       right = new BinaryTree(val);
       return;
     }
     right->insert(val);
   }
 }
开发者ID:d34th4ck3r,项目名称:Random-Codes,代码行数:15,代码来源:subtree.cpp

示例8: main

int main() {
  BinaryTree tree;
  char option;
  int value;

  do {
    cin >> option;
    switch(option) {
      case 'i':
        cin >> value;
        tree.insert(value);
        break;
      case 's':
        cin >> value;
        tree.search(value);
        break;
      case 'p':
        tree.iterative_print();
        break;
      case 'r':
        tree.recursive_print();
        break;
      default:
        break;
    }
  } while(option != 'q');
}
开发者ID:TylerCline,项目名称:SchoolProjects,代码行数:27,代码来源:main.cpp

示例9: if

int
Clause::insert(const Literal &key,
	BinaryTree<Tuple<Literal, List<Literal> > > &clause)
{
	// check if a class already exists
	Tuple<Literal, List<Literal> > tuple(key, List<Literal>());
	int status = clause.retrieve(tuple);
	if (status == OK)
	{
		if ((status = tuple.data.insertAtEnd(key)) != OK)
			return(status);
		if ((status = clause.update(tuple)) != OK)
			return(status);
	}
	else if (status == NOMATCH)
	{
		if ((status = tuple.data.insertAtEnd(key)) != OK)
			return(status);
		if ((status = clause.insert(tuple)) != OK)
			return(status);
	}
	else
		return(status);

	// update the type
	updateType();

	// all done
	return(OK);
}
开发者ID:ombt,项目名称:ombt,代码行数:30,代码来源:clause.c

示例10: main

int main()
{
    BinaryTree binarytree;
    int arr[10] = {8,9,10,3,2,1,6,4,7,5};
    for(int i = 0;i < 10; i++)
    {
        binarytree.insert(arr[i]);
    }
    int value;
    cin >> value;
    if(binarytree.find(value))
    {
        cout << "search success" << endl;
    }
    else
    {
        cout << "search failed " << endl;
    }
    cin >> value;
    if(binarytree.remove(value))
    {
        cout << "delete success" << endl;
    }
    else 
    {
        cout << "delete failed" << endl;
    }
    return 0;
}
开发者ID:vin120,项目名称:datastructcpp,代码行数:29,代码来源:left_rotate.cpp

示例11: run

 //generates output and puts it in data vector
 void run(){
     while( ((structIsaBTree) ? bt.getCurrentTime()<limit : c.getCurrentTime()<limit) && ((structIsaBTree) ? bt.getHead()!=nullptr : c.getGroupSums()>0) ){
         entry vecPos = (structIsaBTree) ? bt.find() : c.selectRate();
         //std::cout<<vecPos.first<<" "<<vecPos.second.first<<" "<<vecPos.second.second<<"\n";
         if (vecPos.second.second>2){
             if (vecPos.second.second==3){
                 addCreature(creatures[vecPos.second.first-1].get("positionX"));
                 std::vector< entry > nCreature{ {10,{creatures.size(),1}}, {10,{creatures.size(),2}}, {.5,{creatures.size(),3}},{.25,{creatures.size(),4}} };
                 for (int i = 0; i<nCreature.size();i++){
                     (structIsaBTree) ? bt.insert(nCreature[i]) : c.addRate(nCreature[i]);
                 }
             }
             else{
                 (structIsaBTree) ? bt.removeAll(vecPos.second,bt.getHead()) : c.deleteC(vecPos.second.first);
             }
         }
         creatures[vecPos.second.first-1].increment(vecPos.second.second);
         for (int x = 0; x<creatures.size();x++){
            // std::cout<<"creature "<<x+1<<" position "<<creatures[x].get("positionX")<<"\n";
             if (creatures[x].get("dead")!=1)
                 data.push_back({(structIsaBTree) ? bt.getCurrentTime() : c.getCurrentTime() ,creatures[x].get("positionX")});
         }
     }
     std::cout<<"final size: "<<creatures.size()<<"\n";
 }
开发者ID:M0nster5,项目名称:LMU,代码行数:26,代码来源:GillespieAlgorithm.cpp

示例12:

BinaryTree<int> build_a_tree(const int datas[], int numb) {
    cout << "number"  << numb<< endl;
    BinaryTree<int> tree;
    for(int i = 0; i< numb; ++i) {
        tree.insert(datas[i]);
    }
    return tree;
}
开发者ID:gaoyuanhezhihao,项目名称:Some_Data_Structure,代码行数:8,代码来源:main.cpp

示例13: minimalBST

// build a BST with minimal height
void minimalBST(int arr[], int start_idx, int end_idx, BinaryTree & bst){
    if(start_idx > end_idx) return;

    int mid_idx = (start_idx + end_idx)/2;
    bst.insert(arr[mid_idx]);
    minimalBST(arr, start_idx, mid_idx - 1, bst);
    minimalBST(arr, mid_idx+1, end_idx, bst);
}
开发者ID:ysonggit,项目名称:codelib,代码行数:9,代码来源:4-3-minimal_bst.cpp

示例14: main

int main() {
    BinaryTree<int> tree;
    tree.insert(10);
    tree.insert(5);
    tree.insert(3);
    tree.insert(20);
    tree.insert(9);
    tree.insert(18);
    tree.insert(22);
    //tree.showPreOrder();
    std::cout << std::endl;
    tree.saveAsDot("text.txt");
    //tree.rotateLeft();
    tree.saveAsDot("right.txt");
    
    return 0;
}
开发者ID:RoseBrowne,项目名称:Datastructuren2,代码行数:17,代码来源:main.cpp

示例15: main

int main()
{
	BinaryTree tree;
	vector <double> vect;

	tree.insert(12);
	tree.insert(7);
	tree.insert(9);
	tree.insert(10);
	tree.insert(22);
	tree.insert(22);
	tree.insert(24);
	tree.insert(30);
	tree.insert(18);
	tree.insert(3);
	tree.insert(14);
	tree.insert(20);

	tree.inorder(vect);
	for (int i = 0; i < vect.size(); i++)
		cout << vect[i] << " ";
	cout << endl;

	if (tree.search(3.1))
		cout << "3.1 was found in the tree.\n";
	else
		cout << "3.1 was not found in the tree.\n";

	cout << "Size of vect: " << tree.size() << endl;
	cout << "Leaf count of vect: " << tree.leafCount() << endl;

	return 0;
}
开发者ID:Jgro1234,项目名称:StartingOutCPP,代码行数:33,代码来源:PC_19_3.cpp


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