Im having a bit of a problem with my binary search tree. For some reason my pointers arent connecting correctly. I'm pretty sure everything is correct but when i run it I keep getting this as the result.
It inputs the numbers 1 5 7 9.
void insert(string word,vector<treeNode> &x) //*&x
{
bool inserted = true;
int node = 0;
treeNode *t = new treeNode;
treeNode *f = new treeNode;
if(x.size() == 0)
{
t->word=word;
x.push_back(*t);
}
else
{
t=&x[0];
f->word=word;
while(inserted)
{
if(word == t->word)
{
t->count++;
inserted = false;
break;
}
if(word > t->word)
{
if (t->right == NULL)
{
t->right=f;
x.push_back(*f);
inserted = false;
}else{ t=t->right; }
}
else {
if (t == NULL)
{
t->left=f;
x.push_back(*f);
inserted = false;
}else{ t=t->left;}
}
}
}
}
Output is this.
Populating Data table...
1 5 7 9
Reading back words
[0] [count 1] 1[] [5]
[1] [count 1] 5[] []
[2] [count 1] 7[] []
[3] [count 1] 9[] []