At line 101 root is returned if leftans and rightans both are not NULL. But even when both the leftans->data==a and rightans->data==a, it returns root, whearas they both should be different. So, it would be better if we write
if (leftans->data == a && rightans->data == b) {
return root;
}
if (leftans->data == b && rightans->data == a) {
return root;
}