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


C++ BSTree类代码示例

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


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

示例1: main

int main()
{
  int N=0;
  cin>>N;
  char ins[20];
  int a,b;
  BSTree tree;
  for(int i=0;i<N;i++)
  {
    cin>>ins;
    if(ins[0]=='i')
    {
      cin>>a;
      tree.insertData(a);
      //tree.printByInOrderTraversal();
    }
    if(ins[0]=='d')
    {
      if(ins[6]=='\0')
      {
        cin>>a;
        tree.deletion(a);
        //tree.printByInOrderTraversal();
      }
      else
      {
        if(ins[7]=='l')
开发者ID:GameShare,项目名称:OJProblem,代码行数:27,代码来源:bst.cpp

示例2: main

int main(){
  const int input[] = {8, 58, 71, 18, 31, 32, 63, 92, 43, 3, 91, 93, 25, 80, 28};
  // output should be array of {18 63 80 25 32 43 80 93 80 25 93 -1 28 -1 -1}
  const int arraysize = sizeof(input) / sizeof(input[0]);
  print_array(input, arraysize);
 
  // test naive method
  int output[arraysize];
  replace_with_least_greater_number(input, arraysize, output);
  print_array(output, arraysize);

  // test BST method
  int output2[arraysize];
  BSTree tree;
  for(int i= arraysize-1; i>=0; i--){
    Node* least_greater_predecessor = tree.insert(input[i]);
    if (least_greater_predecessor == NULL){
      output2[i] = -1;
    }else{
      output2[i] = least_greater_predecessor->value;
    }
  }
  
  //tree.print_tree();
  print_array(output2, arraysize);
  return 0;
}
开发者ID:ysonggit,项目名称:codelib,代码行数:27,代码来源:replace_with_least_greater_num.cpp

示例3: main

int main()
{
	BSTree<int> bstree;
	TreeNode<int>* ptn;

	bstree.insert(3);
	bstree.insert(3);
	bstree.insert(1);
	bstree.insert(7);
	bstree.insert(5);
	bstree.insert(8);
	
	bstree.print(std::cout);
	
	ptn = bstree.find_min(0);
	std::cout << "\nThe minimum element is " << ptn->element << std::endl;
	
	ptn = bstree.find_max(0);
	std::cout << "\nThe maximum element is "  << ptn->element << std::endl;
	
	bstree.delete_element(3);
	bstree.print(std::cout);

	return 0;
}
开发者ID:9426zl,项目名称:Data-Structures-and-Algorithm,代码行数:25,代码来源:binarysearchtree_test.cpp

示例4: main

int main()
{
	int num;
	BSTree T;
	cin >> num;
	while( num != -1 )
	{
		T.insert(num);
		cin >> num;
	}
	T.median();
}
开发者ID:vikas-reddy,项目名称:iiith-programming,代码行数:12,代码来源:median.cpp

示例5: Test2

void Test2()
{
	int a[] = { 5, 3, 4, 1, 7, 8, 2, 6, 0, 9 };
	BSTree<int, int> bst;
	for (int i = 0; i < (sizeof(a) / sizeof(a[0])); ++i)
	{
		bst.InsertR(a[i], i);
	}
	bst.Inorder();
	cout << bst.FindR(0)->_key << endl;
	cout << bst.RemoveR(3) << endl;
}
开发者ID:JulyShuofeng,项目名称:gitcode,代码行数:12,代码来源:test.cpp

示例6: Test1

void Test1()
{
	int a[] = { 5, 3, 4, 1, 7, 8, 2, 6, 0, 9 };
	BSTree<int, int> bst;
	for (int i = 0; i < (sizeof(a) / sizeof(a[0])); ++i)
	{
		bst.Insert(a[i], i);
	}
	bst.Inorder();
	//cout << bst.Find(10)->_key << endl;
	cout << "------------------------------------------" << endl;
	cout<<bst.Remove(8)<<endl;
	bst.Inorder();
}
开发者ID:JulyShuofeng,项目名称:gitcode,代码行数:14,代码来源:test.cpp

示例7: main

int main()
{
	BSTree T;
	int n;
	cin >> n;
	while(n!=-1)
	{
		T.insert(n);
		cin >> n;
	}
	cin >> T.max;
	T.pathsum(T.root);
	cout << T.count << endl;
}
开发者ID:vikas-reddy,项目名称:iiith-programming,代码行数:14,代码来源:pathsum.cpp

示例8: SetTreePositions

//template <typename T>
void SetTreePositions(const BSTree &tree, 
                      std::map<const BSTree::BinTreeNode *, 
                      std::pair<int, int> >& NodePositions)
{
  Position = 0;
  NodePositions.clear();
  SetTreePositions(tree.root(), 0, NodePositions);
}
开发者ID:HBreithaupt,项目名称:DigiPenCode,代码行数:9,代码来源:driver-sample-ints.cpp

示例9: main

int main() {
  BSTree tree;
  tree.Insert(8);
  tree.Insert(6);
  tree.Insert(10);
  tree.Insert(5);
  tree.Insert(7);
  tree.Insert(9);
  tree.Insert(11);

  tree.BreadthFirstTraversal();
  //tree.Rotate();
  //tree.BreadthFirstTraversal();
  tree.RotateIterative2();
  tree.BreadthFirstTraversal();
}
开发者ID:pennymaxlw,项目名称:Algorithms_and_Data_Structures,代码行数:16,代码来源:ms100_015_016.cpp

示例10: main

int main()
{
	BSTreeNode * pHead = NULL;
	BSTreeNode * pListIndex = NULL;
	BSTree* pRoot = new BSTree();
	pRoot->addBSTreeNode(10);
	pRoot->addBSTreeNode(4);
	pRoot->addBSTreeNode(12);
	pRoot->addBSTreeNode(14);
	pRoot->addBSTreeNode(15);
	pRoot->addBSTreeNode(6);
	pRoot->addBSTreeNode(8);
	pRoot->addBSTreeNode(16);
	pRoot->showTree(); // 树的形状
	pRoot->ergodicBSTree();
	return 0;
}
开发者ID:mounsurf,项目名称:Algorithm,代码行数:17,代码来源:main.cpp

示例11: initValues

void initValues(vector <int>& v, BSTree& root, HashTable& ht) {
    int i, randomValue;
    bool hashTableFull;

    for (i = 0; i < size; i++) {
        randomValue = 1 + rand() % 99;
        v.push_back(randomValue);
        root.insert(randomValue);
        hashTableFull = ht.insert(randomValue);
        if (!hashTableFull) cout << "Hash Table is now full." << endl;
    }
}
开发者ID:Nobusada,项目名称:ORI-UFSCar-2015,代码行数:12,代码来源:main.cpp

示例12: Execute

void WithdrawlOrder::Execute(BSTree &accounts)
{
	Account* temp;
	if (accounts.Retrieve(accountID, temp))
	{
		temp->Withdraw(amount, fundNumber);
	}
	else
	{
		cerr << "ERROR: Account " << accountID << " not found. Withdrawl refused." << endl;
	}
}
开发者ID:mgr44,项目名称:Banker-program,代码行数:12,代码来源:WithdrawlOrder.cpp

示例13: main

int main() {
    BSTree<int> tree;
    tree.add(15, 15);
    tree.add(8, 8);
    tree.add(6, 6);
    tree.add(7, 7);
    tree.add(12, 12);
    tree.add(11, 11);
    tree.add(9, 9);
    tree.add(20, 20);
    tree.add(18, 18);
    tree.add(25, 25);
    tree.add(23, 23);

    tree.traverse(TraverseOrder::MID_ORDER);
    tree.traverse(TraverseOrder::PRE_ORDER);

    return 0;
}
开发者ID:KJTang,项目名称:Algorithm,代码行数:19,代码来源:main.cpp

示例14: Test1

void Test1()
{
	BSTree<int, int> b;
	int a[] = { 1, 3, 6, 7, 2, 8, 0 };
	for (int i = 0; i < sizeof(a) / sizeof(a[0]); ++i)
	{
		b.InsertR(a[i], i);
	}
	b.InOder();
	cout<<b.IsBlanceTree()<<endl;
	b.RemoveR(7);
	b.RemoveR(6);
	b.RemoveR(8);
	b.RemoveR(0);
	b.RemoveR(3);
	b.RemoveR(2);
	b.RemoveR(1);
	b.InOder();
	return;
}
开发者ID:Mr-Yuxuan,项目名称:Marvelous-Inventions,代码行数:20,代码来源:test.cpp

示例15: main

int main(int args,char* argv[]){


	BSTree * myTree = new BSTree;
	myTree->Insert(80);
	myTree->Insert(43);
	myTree->Insert(21);
	myTree->Insert(42);
	myTree->Insert(20);
	myTree->Insert(50);
	myTree->Insert(6);
	myTree->Insert(74);
	myTree->Insert(12);
	myTree->Insert(78);
	myTree->Insert(52);

	myTree->InOrder();
	cout << endl;
	myTree->PostOrder();
	cout << endl;
	myTree->PreOrder();
	cin.get();
	return 0;
}
开发者ID:ManosAgelidis,项目名称:BinarySearchTree,代码行数:24,代码来源:main.cpp


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