struct node* searchParent(struct node* root, int x)
{
if(root->left_child->data == x || root->right_child->data == x)
{
return root;
}
else
{
return searchParent(root->left_child, x);
return searchParent(root->left_child, x);
}
}
struct node
{
int data; //node will store an integer
struct node *right_child; // right child
struct node *left_child; // left child
};
struct node* searchParent(struct node* root, int x)
{
if((root->left_child != NULL && root->left_child->data == x) || (root->right_child != NULL && root->right_child->data == x))
{
return root;
}
else
{
if(root->left_child != NULL && x < root->data)
{
return searchParent(root->left_child, x);
}
else
if(root->right_child != NULL && x > root->data)
{
return searchParent(root->right_child, x);
}
}
}
If(root->data < x) return searchParent(root->left_child, x);
Else return searchParent(root->right_child, x);