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


C++ AVL::size方法代码示例

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


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

示例1: testAVL

/******************************************************************************************
 * Test an AVL
 ******************************************************************************************/
template <typename T> void  testAVL(int n) {
   AVL<T>* avl = new AVL<T>;
   while (avl->size() < n) {
      T e = dice((T)n*3); //[0, 3n)范围内的e
      switch (dice(3)) {
         case 0: { //查找,成功率 <= 33.3%
            printf("Searching for "); print(e); printf(" ...\n");
            BinNodePosi(T) & p = avl->search(e);
            p ?
               printf("Found with"), print(p), printf("\n") :
               printf("Not found\n");
            break;
         }
         case 1: { //删除,成功率 <= 33.3%
            printf("Removing "); print(e); printf(" ...\n");
            avl->remove(e) ? printf("Done\n"), print(avl) : printf("Not exists\n");
            break;
         }
         default: {//插入,成功率 == 100%
            printf("Inserting "); print(e); printf(" ...\n");
            BinNodePosi(T) p = avl->insert(e);
            printf("Done with"), print(p), printf("\n"), print(avl);
            break;
         }
      }
   }
   while (avl->size() > 0) {
      T e = dice((T)n*3); //[0, 3n)范围内的e
      printf("Removing "); print(e); printf(" ...\n");
      avl->remove(e) ? printf("Done\n"), print(avl) : printf("Not exists\n");
   }
   release(avl);
}
开发者ID:tantantzp,项目名称:datastructure,代码行数:36,代码来源:main.cpp

示例2: main

int main(int argc, char **argv)
{
	int i, j, n;
	double t;
	AVL<int> tree;
	if (argc > 3) return EXIT_FAILURE;
	i = time(0);
	if (argc == 1) n = 20;
	else {
		n = atoi(argv[1]);
		if (argc == 3) i = atoi(argv[2]);
	}
	srand((unsigned int)i);
	cout << "Size is " << n << endl;
	cout << "Seed is " << i << endl;
	cout << "Inserting..." << endl;
	t = ((double)clock())/CLOCKS_PER_SEC;
	for (i = 1 ; i <= n ; i++) {
		j = rand()%n+1;
	//	cout << j << ' ';
		tree.insert(j);
	}
	t = ((double)clock())/CLOCKS_PER_SEC-t;
	cout << t << " secs" << endl;
//	cout << "\nPrinting tree..." << endl;
//	tree.print();
	cout << "Size of tree is: " << tree.size() << endl;
	ofstream out("avl.dot");
	tree.display(out);
	out.close();
	system("dot avl.dot -Tpng -o avl.png");
	cout << "Created tree image at avl.png!" << endl;
	cout << "Extracting..." << endl;
	t = ((double)clock())/CLOCKS_PER_SEC;
	for (i = 1 ; i <= n ; i++) {
		j = rand()%n+1;
	//	cout << j << ' ';
		tree.extract(j);
	}
	t = ((double)clock())/CLOCKS_PER_SEC-t;
	cout << t << " secs" << endl;
//	cout << "\nPrinting tree..." << endl;
//	tree.print();
	cout << "Size of tree is: " << tree.size() << endl;
	cout << "Clearing..." << endl;
	t = ((double)clock())/CLOCKS_PER_SEC;
	tree.clear();
	t = ((double)clock())/CLOCKS_PER_SEC-t;
	cout << t << " secs" << endl;
	return EXIT_SUCCESS;
}
开发者ID:mmdsharifi,项目名称:trees,代码行数:51,代码来源:recursive-avl-tree.cpp

示例3: printTreeStatus

void printTreeStatus(const AVL<T> &t) {
    cout << "----------------------------------------" << endl;
    if (t.isEmpty()) cout << "The tree is empty" << endl;
    else {
        cout << "Tree root is: " << t.root() << endl;
        cout << "Tree height is: " << t.height() << endl;
        cout << "Tree contains " << t.size() << " elements" << endl;
    }
    cout << "----------------------------------------" << endl;
}
开发者ID:0x0all,项目名称:algorithms-1,代码行数:10,代码来源:avl_demo.cpp


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