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


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

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


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

示例1: _tmain

int _tmain(int argc, _TCHAR* argv[])
{
    BinaryTree* pTree = new BinaryTree();
    pTree->Insert(5);
    pTree->Insert(15);
    pTree->Insert(50);
    pTree->Insert(52);
    pTree->Insert(25);
    pTree->Insert(3);
    pTree->Insert(2);
    pTree->Insert(1);

    int results[256];

    pTree->BinaryTreeToArray(results, 256); 

	return 0;
}
开发者ID:cmccoll,项目名称:Algorithms,代码行数:18,代码来源:Main.cpp

示例2: main

int main()
{
	BinaryTree<double> bt;

	bt.Insert(6.1);
	bt.Insert(4.1);
	bt.Insert(2.1);
	bt.Insert(5.1);
	bt.Insert(1.1);
	bt.Insert(3.1);
	bt.Insert(7.1);

	cout << "Is Binary Search Tree " << (bt.IsBinarySearchTree() == false ? ": False" : ": True") << endl;

	bt.TestLCA();

	return 0;
}
开发者ID:ankitufl,项目名称:Practice,代码行数:18,代码来源:LowestCommonAncestor.cpp

示例3: main

int main()
{
	BinaryTree bt;

	bt.Insert(5);
	bt.Insert(3);
	bt.Insert(7);
	bt.Insert(2);
	bt.Insert(1);
	bt.Insert(8);
	bt.Insert(9);

	bt.Print();

	string res = bt.IsBST() ? "is" : "is not";

	cout << "The binary tree " << res << " a binary search tree" << endl;

	return 0;
}
开发者ID:ankitufl,项目名称:Practice,代码行数:20,代码来源:IsBST.cpp

示例4: main

int main()
{
  int foo[] = {1, 2, 3, 4, 5, 6};
  int size = sizeof (foo) / sizeof (int);
  BinaryTree tree (foo, size - 1);
  for (int i = 7; i < 10; i++)
    tree.Insert (i);
  printf ("height is %d factor is %d\n", tree.getHeight(),tree.getFactorI() );
  
  tree.PrintTreePostOrder();
  printf ("\n");
}
开发者ID:cdht,项目名称:Algorithm,代码行数:12,代码来源:BinaryTree(AVL+NR).cpp

示例5: TestIntTree

void TestIntTree()
{
    BinaryTree<int> tree;
    
    cout << "Testing ints, inserting:" << endl;
    srand(time(0));
    for (int i = 0; i < 20; ++i)
    {
        int data = rand() % 100;
        cout << data << ", ";
        tree.Insert(data);
    }
    outputTree(tree);
}
开发者ID:petemulholland,项目名称:learning,代码行数:14,代码来源:main.cpp

示例6: TestRootInsertion

void TestRootInsertion()
{
    BinaryTree<int> tree;
    
    cout << "Testing root insertion with rotation:" << endl;
    srand(time(0));
    for (int i = 0; i < 20; ++i)
    {
        int data = rand() % 100;
        cout << "Inserting: " << data << endl;
        tree.Insert(data);
        tree.inOrderGraph();
    }
}
开发者ID:petemulholland,项目名称:learning,代码行数:14,代码来源:main.cpp

示例7: TestFloatTree

void TestFloatTree()
{
    BinaryTree<float> tree;
    
    cout << "Testing floats, inserting:" << endl;
    srand(time(0));
    for (int i = 0; i < 20; ++i)
    {
        float data = (rand() % 10000) / 100.0; 
        cout << data << ", ";
        tree.Insert(data);
    }
    outputTree(tree);
}
开发者ID:petemulholland,项目名称:learning,代码行数:14,代码来源:main.cpp

示例8: main

// test for binarytree class
void main() {
	BinaryTree btree;
	vector<int> insertData = {5,2,6,4,8,1,0,14,9,7};
	int length = insertData.size();
	for (int i = 0; i < length;i++) {
		btree.Insert(insertData[i]);
	}
	cout << "Tree size is :" << btree.size() << endl;
	cout << "Looking up..." << endl;
	btree.look_up(7);
	cout << "BFS..." << endl;
	btree.printBFS();
	cout << "Pre-order..." << endl;
	btree.printPre_order();
}
开发者ID:yonghangyu,项目名称:DataStructure,代码行数:16,代码来源:main.cpp

示例9: TestCopyCtor

void TestCopyCtor()
{
    BinaryTree<int> tree;
    
    cout << "Testing ints, inserting:" << endl;
    srand(time(0));
    for (int i = 0; i < 20; ++i)
    {
        int data = rand() % 100;
        cout << data << ", ";
        tree.Insert(data);
    }
    cout << "Original tree:" << endl;
    tree.inOrderGraph();

    BinaryTree<int> copy(tree);
    cout << "Copied tree:" << endl;
    copy.inOrderGraph();
}
开发者ID:petemulholland,项目名称:learning,代码行数:19,代码来源:main.cpp

示例10: TestCharTree

void TestCharTree()
{
    BinaryTree<char> tree;
    
    cout << "Testing chars, inserting:" << endl;
    srand(time(0));
    for (int i = 0; i < 20; ++i)
    {
        char data = rand() % 62;
        if (data < 10)
            data += 48;
        else if (data < 36)
            data += 55; // 65 - 10
        else 
            data += 61; // 97 - 36
        
        cout << data << ", ";
        tree.Insert(data);
    }
    outputTree(tree);
}
开发者ID:petemulholland,项目名称:learning,代码行数:21,代码来源:main.cpp

示例11: main

int main(int argc, char* argv[])
{
#ifdef _DEBUG
	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif

	BinaryTree<int>* pSearchTree = new BSearchTree<int>;

	pSearchTree->Insert(1);
	pSearchTree->Insert(2);
	pSearchTree->Insert(3);
	pSearchTree->Insert(4);
	pSearchTree->Insert(5);
	pSearchTree->Insert(6);
	pSearchTree->Insert(7);

	BTreeTraverse<int> Traverse;
	cout<<"Search Tree level order traverse:"<<endl;
	Traverse.LevelOrderTraverse(*pSearchTree, PrintElement);

	BinaryTree<int>* pAvlTree = new CAVLTree<int>;

	pAvlTree->Insert(1);
	pAvlTree->Insert(2);
	pAvlTree->Insert(3);
	pAvlTree->Insert(4);
	pAvlTree->Insert(5);
	pAvlTree->Insert(6);
	pAvlTree->Insert(7);

	cout<<"AVLTree level order tree: "<<endl;
	Traverse.LevelOrderTraverse(*pAvlTree, PrintElement);

	system("pause");
	return 0;
}
开发者ID:Littlegrace111,项目名称:DataStructure_Algorithm,代码行数:36,代码来源:BalanceTreeTest.cpp

示例12: main

//Compile using g++ ./main.cpp -std=c++14 -o ./test
int main( int argc, char* argv[] )
{
  BinaryTree<int64_t> bst;

  for( auto i : {30,0,10,-15,1,29})
    bst.Insert( i );
  bst.InOrderTraversal();

  /*std::cout <<"Mokay, now deleting "<<std::endl;
  for( auto i : {30,0,10,-15,1,29})
    bst.Delete(i);
  std::cout << "Result after deletion is (should be blank): "<<std::endl;
  bst.InOrderTraversal();*/

  //Get the successor of v
  int v = 0;
  auto n = bst.GetSuccessor(v);
  if (n)
    std::cout << "Successor of "<<v<<" is "<<n->m_idx<<std::endl;
  else
    std::cout << "There is no successor to "<<v<<std::endl;
  return EXIT_SUCCESS;
}
开发者ID:gnthibault,项目名称:EPI,代码行数:24,代码来源:main.cpp


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