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


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

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


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

示例1: dist

TEST(AVLTree, Insert) {
  {
  AVLTree<int, int> a;

  for (int i = 0; i < 1000; i++) {
    a.Insert(i, i * i);
    for (int k = 0; k <= i; k++) {
      ASSERT_EQ(a.Find(k).first, k * k);
      ASSERT_TRUE(a.Find(k).second);
    }
  }
  }
  {
  AVLTree<int, int> a;

  for (int i = 100; i > 0; i--) {
    a.Insert(i, i * i);
    for (int k = i; k <= 100; k++)
      ASSERT_EQ(a.Find(k).first, k * k);
  }
  }
  AVLTree<int, int> b;
  mt19937_64 _e1(chrono::system_clock::now().time_since_epoch().count());
  std::uniform_int_distribution<int> dist(0, 1000000);
  for (int i = 0; i < 1000; i++) {
    int t = dist(_e1);
    b[t] = i * i;
    ASSERT_EQ(b.Find(t).first, i * i);
  }
}
开发者ID:Zaspire,项目名称:libshelly,代码行数:30,代码来源:avl_tree_test.cpp

示例2: TestAVLTree

void TestAVLTree()
{
	int arr[] = { 4, 2, 6, 1, 3, 5, 15, 7, 16, 14 };
	// int arr[] = { 16, 3, 7, 11, 9, 26, 18, 14, 15 };
	AVLTree<int, int> tree;
	for (size_t i = 0; i < sizeof(arr) / sizeof(arr[0]); i++)
	{
		tree.Insert(arr[i]);
	}
	tree.InOrder();
}
开发者ID:muhuizz,项目名称:Data_Structure,代码行数:11,代码来源:AVLTree.hpp

示例3: main

int main()
{
	AVLTree al;
	for (int i = 1; i < 10; i ++) {
		al.Insert(i);
		
	}
	al.Print();
	for (int i = 1; i < 10; i += 2) {
		al.Delete(i);
		al.Print();
	}
	return 0;
}
开发者ID:chambakari,项目名称:Introduction-of-Algorithms,代码行数:14,代码来源:AVL_Tree.cpp

示例4: main

int main()
{
	AVLTree* t = new AVLTree();
	std::vector<Handle> v;
	int n = 15;
	for(size_t i=0; i < n; ++i)
	{
		v.push_back(t->Insert(i));
		t->PrintKvalue(1);
	}
	std::cout << std::endl;
	for(size_t i=0; i < n; ++i)
	{
		t->Remove(v[i]);
	}
	delete t;
	return 0;
}
开发者ID:asaitgalin,项目名称:LaradeRepo,代码行数:18,代码来源:AVL_TREE.cpp

示例5: avl_tree

void avl_tree()
{
    AVLTree<int> avl;
    
#define AVL_LOOP for (int i = 0; i <10; i ++)

	AVL_LOOP
    {
		avl.Insert(i);
    }

	AVL_LOOP
	{
		 avl.Delete(i);
	}

	AVL_LOOP
	{
		assert(!avl.Exists(i));
	}
}
开发者ID:dbremner,项目名称:airhan,代码行数:21,代码来源:main.cpp

示例6: main

int main(int argc,char*argv[])
{
	AVLTree<string> avlTree;
	BSTree<string> bsTree;
	string str, last;
	char c;

	if (argc != 2)
	{
		cerr << "Parameters: <filename>.  use quotations around long path names." << endl;
		return 1;
	}

	ifstream ifsInput(argv[1],ios::in | ios::binary);

	if (!ifsInput)
	{
		cerr << "Couldn't open input file." << endl;
		return 2;
	}

	
	while (ifsInput.get(c) && !ifsInput.eof())
	{
		switch (c)
		{
			case '.':
			case ',':
			case '\'':
			case '\"':
			case ':':
			case ';':
			case '<':
			case '>':
			case '/':
			case '?':
			case '[':
			case ']':
			case '{':
			case '}':
			case '\\':
			case '|':
			case '!':
			case '#':
			case '$':
			case '%':
			case '^':
			case '&':
			case '*':
			case '(':
			case ')':
			case '_':
			case '=':
			case '`':
			case ' ':
			case '\r':
			case '\n':
			case '\t':
				if (str.size())
				{
					avlTree.Insert(str);
					bsTree.Insert(str);
					last = str;
				}
				
				str = "";
				continue;
			default:
				str += c;
				continue;
		}

	}
	ifsInput.close();
	//x.Output(Print);
	cout << "AVL Height: " << avlTree.Height() << endl;
	cout << "BST Height: " << bsTree.Height() << endl;
	cout << "AVL Size:   " << avlTree.Size() << endl;
	cout << "BST Size:   " << bsTree.Size() << endl;


	clock_t stime, etime;
	double elapse; 
	int i;
	
	cout << "Searching for \"" << last << "\"..." << endl;
	stime = clock();
	for (i = 0; i < 100000; i++)
		avlTree.Find(last);
	etime = clock();
	elapse =(double)(etime-stime)/CLOCKS_PER_SEC;
	cout << "Search in AVL tree took " << elapse << " seconds " << endl;


	stime = clock();
	for (i = 0; i < 100000; i++)
		bsTree.Find(last);
	etime = clock();
	elapse =(double)(etime-stime)/CLOCKS_PER_SEC;
	cout << "Search in BST tree took " << elapse << " seconds " << endl;
//.........这里部分代码省略.........
开发者ID:nacitar,项目名称:old-projects,代码行数:101,代码来源:driver.cpp

示例7: main

int main()
{
	AVLTree<int> itree;

	std::cout << "Insert 0 9 4 6 -4 -2 -1\n";
	itree.Insert(0);
	itree.Insert(9);
	itree.Insert(4);
	itree.Insert(6);
	itree.Insert(-4);
	itree.Insert(-2);
	itree.Insert(-1);
	
	std::cout << "InOrder traverse:\n";
	itree.InOrderTraverse();
	std::cout << "PreOrder traverse:\n";
	itree.PreOrderTraverse();

	std::cout << "Deleted 9:\n";
	itree.Delete(9);
	std::cout << "InOrder:\n";
	itree.InOrderTraverse();
	std::cout << "PreOrder:\n";
	itree.PreOrderTraverse();

	std::cout << "Deleted 4:\n";
	itree.Delete(4);
	std::cout << "InOrder:\n";
	itree.InOrderTraverse();
	std::cout << "PreOrder:\n";
	itree.PreOrderTraverse();

	std::cout << "Deleted 0:\n";
	itree.Delete(0);
	std::cout << "InOrder:\n";
	itree.InOrderTraverse();
	std::cout << "PreOrder:\n";
	itree.PreOrderTraverse();

	std::cout << "Deleted -2:\n";
	itree.Delete(-2);
	std::cout << "InOrder:\n";
	itree.InOrderTraverse();
	std::cout << "PreOrder:\n";
	itree.PreOrderTraverse();

	std::cout << "Deleted 6:\n";
	itree.Delete(6);
	std::cout << "InOrder:\n";
	itree.InOrderTraverse();
	std::cout << "PreOrder:\n";
	itree.PreOrderTraverse();
//-----------------------------------------------------------------------------------------
	AVLTree<std::string> strTree;

	std::cout << "Inserted 5 string: rensehngqiang shibojun lijin wangzaibing zhaogang\n";
	strTree.Insert("renshengqiang");
	strTree.Insert("shibojun");
	strTree.Insert("lijin");
	strTree.Insert("wangzaibing");
	strTree.Insert("zhaogang");

	std::cout << "InOrder traverse:\n";
	strTree.InOrderTraverse();
	std::cout << "PreOrder traverse:\n";
	strTree.PreOrderTraverse();

	std::cout << "Look for lijin:\n";
	AVLTreeNode<std::string> *pNode = strTree.Search("lijin");
	if(pNode != 0) std::cout << pNode->element << std::endl;

	std::cout << "Look for huangliangyu\n";
	pNode = strTree.Search("huangliangyu");
	if(pNode != 0) std::cout << pNode->element << std::endl;

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

示例8: main

int main()
{
	AVLTree<int, std::string> itree;

	std::cout << "Insert 0 9 4 6 -4 -2 -1\n";
	itree.Insert(0, "zero");
	itree.Insert(9, "nine");
	itree.Insert(4, "four");
	itree.Insert(6, "six");
	itree.Insert(-4, "negtive 4");
	itree.Insert(-2, "negtive -2");
	itree.Insert(-1, "negtive -1");
    
    std::cout << "traverse through thread info:\n";
    typename BSTree<int, std::string>::BSTreeNode *firstNode = itree.GetFirstNode();
    while(firstNode){
        std::cout << "<" << firstNode->key << ", " << firstNode->value << "> ";
        firstNode = firstNode->next;
    }
    std::cout << "\n-----------------------------\n";

	std::cout << "InOrder traverse:\n";
	itree.InOrderTraverse();
	std::cout << "PreOrder traverse:\n";
	itree.PreOrderTraverse();

	std::cout << "Deleted 9:\n";
	itree.Delete(9);
	std::cout << "InOrder:\n";
	itree.InOrderTraverse();
	std::cout << "PreOrder:\n";
	itree.PreOrderTraverse();

	std::cout << "Deleted 4:\n";
	itree.Delete(4);
	std::cout << "InOrder:\n";
	itree.InOrderTraverse();
	std::cout << "PreOrder:\n";
	itree.PreOrderTraverse();

	std::cout << "Deleted 0:\n";
	itree.Delete(0);
	std::cout << "InOrder:\n";
	itree.InOrderTraverse();
	std::cout << "PreOrder:\n";
	itree.PreOrderTraverse();

	std::cout << "Deleted -2:\n";
	itree.Delete(-2);
	std::cout << "InOrder:\n";
	itree.InOrderTraverse();
	std::cout << "PreOrder:\n";
	itree.PreOrderTraverse();

	std::cout << "Deleted 6:\n";
	itree.Delete(6);
	std::cout << "InOrder:\n";
	itree.InOrderTraverse();
	std::cout << "PreOrder:\n";
	itree.PreOrderTraverse();

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


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