Hello,
I create a bst with the following code:
class BinarySearchTree
{
public:
struct tree_node
{
string code;
float min;
float max;
tree_node* left;
tree_node* right;
};
tree_node* root;
BinarySearchTree() {
root = NULL;}
bool isEmpty() const { return root==NULL; }
};
The tree is sorted according to the min value, but i want to search the tree with the code value. Obviously i have to check all nodes recursively , and if i found the code i must return two pointers, one for the target node (tree_node* target) and one more for his parent (tree_node* parent).
I am trying to define a function with the following code...
void BinarySearchTree::find(string cod, tree_node* tree, tree_node* target, tree_node* parent, bool& found) {
if(tree != NULL && !found){
if(tree->left->code == cod || tree->right->code == cod) {
parent=tree;
found = true;
if (tree->left->code == cod)
target = tree->left;
else
target = tree->right;
}
else {
if(tree->left) find(cod,tree->left,target,parent,found);
if(tree->right) find(cod,tree->right,target,parent,found);
}
}
}
Can you help me, to define the find function ?
Thanks in advance !