# BST, anyone see whats wrong?

Anyone know whats wrong with my code?
Wanting to keep a frequency count on each word.  Its not incrementing right or frequency is not initialized right or something.

Any ideas?

###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
You have a frequency variable for each Node, yet you initialize frequency = 0 in your Tree constructor and did not get a compile error? That's where the error lies.
Commented:
Also, in your InsertItem, I don't know what the purpose of setting current = t is, but you seem to want to point it to the newly created Node. If that's the case, then your line current = t; should be in the same else loop with your allocation.
>>else {
>>   t = new TreeNode(Item,0,0);
>>   current = t;
>>}
and not outside of it. Otherwise your pointer current will be misplaced since there possibly will me many recursive calls before it waiting to finish up.
Commented:
In your findNode, using return would be a safer habit than break.
>>if (current->data == searchItem) {
>>        break; // found match, store in BST current ptr
>>}
Author Commented:
So frequency should not be initialized to anything?
Commented:
The best logic is: your frequency variable belongs to class TreeNode, thus it should be initialized by that class itself. So allow your TreeNode constructor to do frequency = 0 for you. Remember if you have n Nodes that's n frequency variables for you.
Commented:
TreeNode(T newT, TreeNode *l, TreeNode *r)
{
data = newT;
left = l;
right = r;
frequency = 0;
}

Experts Exchange Solution brought to you by