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


C++ BSTree::Find方法代码示例

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


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

示例1: TestBSTree

void TestBSTree()
{	
	// 5 3 4 1 7 8 2 6 0 9
	BSTree<int, double> t;
	t.Insert(5,5);
	t.Insert(3,3);
	t.Insert(4,4);
	t.Insert(1,1);
	t.Insert(7,7);
	t.Insert(8,8);
	t.Insert(2,2);
	t.Insert(6,6);
	t.Insert(0,0);
	t.Insert(9,9);

	t.PrevOrder();

	BSTNode<int,double>* ret = t.Find(9);
	cout<<"Find 9 ?: "<<ret->_key<<endl;
	ret = t.Find(10);
	cout<<"Find 10 ?: "<<ret<<endl;

	t.Remove(8);
	t.Remove(1);
	t.Remove(5);

	t.PrevOrder();
}
开发者ID:changfeng777,项目名称:DataStruct,代码行数:28,代码来源:BinarySearchTree.hpp

示例2: 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

示例3: main


//.........这里部分代码省略.........
    }
     cout << "Done: Insert" << endl
     <<"*************************"<<endl
     <<"Test: Depth"<<endl;

    unsigned bd = bst.Depth();
    const unsigned CD = 46;
    if ( Final_Test && bd != CD )
    {
      cout << "bst depth: " << bst.Depth() << endl;
      cout << "Correct Depth: " << CD<<endl
           <<"<enter> to continue"<<endl;
      cin.get();

    }
    cout << "Done: Depth"<<endl
    <<"*************************"<<endl
    <<"Test: Traversals"<<endl;
    least = recs_inorder[least_rec];
    pcnt = 0;
    bst.InOrderTraversal(Inord);
    cout << "   Done: In order traversal #1"<<endl;

    ord_cnt = 0;
    bst.PreOrderTraversal(Preord);
    cout << "   Done: Pre order traversal #1"<<endl;

    ord_cnt = 0;
    bst.PostOrderTraversal(Postord);

    cout << "   Done: Post order traversal #1"<<endl
    <<"Done: Traversals"<<endl
    <<"*************************"<<endl
    <<"Test: Find"<<endl;


    for ( unsigned i=0; i<recs_read; i++ )
    {
       Record ret = bst.Find(keys[i]);
       if ( ret.Key() != keys[i] )
       {
         cout <<i<< "  Find Error. You found the Record with key: "
         << ret.Key() <<endl<< " when searching for key: "
         << keys[i] << endl
         <<"<enter> to continue"<<endl;
         cin.get();
       }
    }
    cout << "Done: Find"<<endl
    <<"*************************"<<endl
    <<"Test: Find bad key"<<endl;


    KeyType bad_key("~badkey"); //to the right
    Record BK = bst.Find(bad_key);
    KeyType KNF("KEY NOT FOUND");
    if ( BK.Key() != KNF  )
    {
      cout << "Looking for bad Key: " << bad_key<<endl;
      cout << "  you found: " << BK << endl
      <<"<enter> to continue"<<endl;
      cin.get();
    }
    bad_key[0] = 0; //to the left
    BK = bst.Find(bad_key);
    if ( BK.Key() != KNF  )
开发者ID:dzackgarza,项目名称:Trees,代码行数:67,代码来源:BSTmain.cpp


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