[Solved] Search function returns the same regardless of item present in the binary search tree


Your code invoke UB.

tree_node *root;
...
c=b.search(root,number);  // root is uninitialized

To solve this add a new function:

class bst
{
    ...
    int search(tree_node * ,int);
    int search(int v) {
        return search(root, v);
    }
};

Also in bst::search function:

else //if (root != NULL){  Comment this condition
if(root->data == data) {
   //   r="t";
    return 1;
}
//} Comment this line

This condition is not only redundant but also make some code flow paths return without value.

1

solved Search function returns the same regardless of item present in the binary search tree