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


C++ AvlTree::searchTree方法代码示例

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


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

示例1: main

int main()
{
	//Assignment 4 part 1

	const int arraySize = 100000;

	int* arr = ArraySearcher::generateArray(arraySize);

	cout << "Results for searches:" << endl;

	auto start = Clock::now(); //start time
	for (int i = 0; i < arraySize; i++)
		ArraySearcher::sequentialSearch(arr, i, arraySize);
	auto end = Clock::now(); //end time

	cout << "Sequential: " << DURATION << " milliseconds" << endl;

	start = Clock::now();
	for (int i = 0; i < arraySize; i++)
		ArraySearcher::binarySearch(arr, i, arraySize);
	end = Clock::now();

	cout << "Binary: " << DURATION << " milliseconds" << endl;
	
	_getch();

	cout << "~~~~~~~~~~~~~~~~~~~~~~" << endl << endl;

	/* Assignment 4 - Part 2 */

	AvlTree tree;

	/* Fill tree with words from dictionary */

	ifstream dictionary("../resources/dictionary.txt");

	if (dictionary.is_open())
	{
		string line;

		while (getline(dictionary, line))
		{
			tree.insertValue(line); 
		}

		dictionary.close();
	}
	else
	{
		cout << "Couldn't open file!" << endl;
	}

	/* Print the full tree */

	cout << "Full dictionary avl tree: " << endl << endl;

	tree.printTree();

	cout << endl << endl << endl;

	/* Checking misspelled words */

	ifstream mispelled("../resources/mispelled.txt");

	if (mispelled.is_open())
	{
		cout << "Mispelled words: " << endl;

		string data;
		getline(mispelled, data);

		char* delim = " ,.!?()#&1234567890\"";
		char* buffer = new char[data.length() + 1];
		strcpy(buffer, data.c_str());
		char* word;

		word = strtok(buffer, delim);

		while (word != NULL)
		{
			int i = 0;
			while (word[i])
			{
				word[i] = tolower(word[i]);
				i++;
			}

			if (!tree.searchTree(word))
			{
				cout << word << endl;
			}

			word = strtok(NULL, delim);
		}

		mispelled.close();
	}
	else
	{
		cout << "Couldn't open file!" << endl;
//.........这里部分代码省略.........
开发者ID:domcull3n,项目名称:School-Work,代码行数:101,代码来源:Source.cpp


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