hello @Yash5646
if(root->left == NULL)
{
if(root->right->data > root->data)
{
minval = root->data;
maxval = root->right->data;
return(make_pair(2, true));
}
else {
maxval = root->data;
minval = root->right->data;
return (make_pair(0, false));
}
}
else if (root->right == NULL)
{
if(root->left->data < root->data) {
maxval = root->data;
minval = root->left->data;
return(make_pair(2, true));
}
else {
maxval = root->right->data;
minval = root->data;
return(make_pair(2, true));
}
}
this cases are wrong.
if left or right is NULL then also there is chance of getting bst of size more than 2.
consider this->
1->2->3->4 (root is 1 and all elements are in right pointers)