// Arne Andersson tree implementation
// By: Nick Cash
// Computer Science III
// For more information on this data type please visit Wikipedia
// Note: This implementation is a string to integer map
// Includes
#include <cstdlib>
#include <iostream>
#include "aa-tree.h"
using namespace std;
// Convert a word to lowercase and remove punctuation
string SmashCasePunct(string str)
{
string temp;
for ( int i = 0; i < str.length(); i++ )
{
if ( ispunct(str[i]) )
continue;
temp += tolower(str[i]);
}
return temp;
}
// This program reads in txt from input until ### is found, and it stores
// words in the tree;
int main()
{
cAATree tree; // Our string-integer map, using an AATree
string word; // Used for input and output
string x;
// Loop until we hit our ending string
while ( true )
{
cin >> word; // Grab word
if ( word == "###" ) // Check to quit
break;
if ( word.length() < 3 ) // Grab length, only count words with length > 2
continue;
x = SmashCasePunct(word); // Smash our case and punctuation
tree.Lookup(x); // Perform the lookup/addition
}
// Print out our data nicely
cout << "\n\nTree contains this data:\n------------------------\n";
tree.Print();
cout << "------------------------\n";
cout << "Total unique words: " << tree.TotalNodes() << endl;
return EXIT_SUCCESS;
}