i was able to make an add functin for a binary tree. in my code, i am able to add a string for the name, university and and int value for an id.
now, i need help being able to search the binary tree for a specified id, then return it if it is found. this is what i have so far,
void MyBST :: search(treenode* r, int& stid, bool& found)
{ if (r == NULL)
found = false;
else if (stid < r->id)
search(r->left, stid, found);
else if (stid > r->id)
search(r->right, stid, found);
else
{
stid = r->id;
found = true;
}
}
what this should do, is look at the root of the tree. if it is the item being searched, display it, if not check whether the item needed is bigger or smaller than the one being looked at. it keeps repeating this process untill the specified number is found. it doesnt seem to work for me, and any help would be greatly appreciated.
thank you