本文整理汇总了C++中AvlTree::printTree方法的典型用法代码示例。如果您正苦于以下问题:C++ AvlTree::printTree方法的具体用法?C++ AvlTree::printTree怎么用?C++ AvlTree::printTree使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AvlTree
的用法示例。
在下文中一共展示了AvlTree::printTree方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
// Test program
int main( )
{
AvlTree<int> t;
int NUMS = 2000000;
const int GAP = 37;
int i;
cout << "Checking... (no more output means success)" << endl;
for( i = GAP; i != 0; i = ( i + GAP ) % NUMS )
t.insert( i );
t.remove( 0 );
for( i = 1; i < NUMS; i += 2 )
t.remove( i );
if( NUMS < 40 )
t.printTree( );
if( t.findMin( ) != 2 || t.findMax( ) != NUMS - 2 )
cout << "FindMin or FindMax error!" << endl;
for( i = 2; i < NUMS; i += 2 )
if( !t.contains( i ) )
cout << "Find error1!" << endl;
for( i = 1; i < NUMS; i += 2 )
{
if( t.contains( i ) )
cout << "Find error2!" << endl;
}
AvlTree<int> t2;
t2 = t;
for( i = 2; i < NUMS; i += 2 )
if( !t2.contains( i ) )
cout << "Find error1!" << endl;
for( i = 1; i < NUMS; i += 2 )
{
if( t2.contains( i ) )
cout << "Find error2!" << endl;
}
cout << "End of test..." << endl;
return 0;
}
示例2: main
int main() {
AvlTree<int> *tree = new AvlTree<int>();
tree->insert(3);
tree->printTree();
}
示例3: 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;
//.........这里部分代码省略.........