You have too many nodes. You want one node per UNIQUE word, not one node per word.
I would rename your class to word or node. You should have one tree and several nodes. You don't want to name something "tree" if there is one "tree" per word, in my opinion. If you have something called tree, make sure there is only one of them.
void insert(mytree*& start, string aword)
{
if(start == NULL)
{
start = new mytree;
start->right = NULL;
start->left = NULL;
start->item = aword;
}
else if(aword < start->item)
insert(start->left, aword);
else
insert(start->right, aword);
}
Nowhere do you compare the value of item to aword to see if they are equal and doing something if they are. You should be adjusting frequency as you insert, not later. New words should have a frequency of 1. Words already in the tree should have their frequencies incremented.
Also, I don't think you can use < with strings. String isn't an ordinal type. Consider using compare if you are trying to alphabetize here:
http://www.cplusplus.com/reference/s...g/compare.html
class node
{
// data members below
node* right;
node* left;
string word;
int frequency;
// one member function below
insert (string aword)
{
// check whether word is the same as aword
// if so, increment frequency, don't create new node.
// if not, check whether to go right or left and if
// child is null, create a new node. Otherwise,
// recurse as you do.
}
// more member functions/constructor
};
class tree
{
// data member
node* top;
// constructor
tree ()
{
top = NULL;
}
void insert (string aword)
{
if (top == NULL)
// create new top node with call to node constructor
else
top->insert (aword);
}
};