What is the functionality of given C program:

int check(struct node* B1, struct node* B2)
{
if(B1 == NULL (A) B2 == NULL) return 1;
if((B1!=NULL (&&) B2==NULL)B(B1==NULL && B2!=NULL)) (X)
if(B1->data == B2->data)
return check(B1->left, B2->left) && check(B1->right, B2->right)(Y)
}

What will be code for A, B, X and Y.
(A) ||, &&, ; return 0;
(B) ||, &&, return 0, ;
(C) &&, ||, return 0; ; respectively.
(D) ||, ||,return 0;, return 0;


Answer: (C)

Explanation: Above code is for checking equality of two binary trees:
int equaltree(struct node* B1, struct node* B2)
{
if(B1 == NULL && B2 == NULL) return 1;
if((B1!=NULL && B2==NULL)||(B1==NULL && B2!=NULL)) return 0;
if(B1->data == B2->data)
return equaltree(B1->left, B2->left) && equaltree(B1->right, B2->right);
}
So, option (C) is correct.

Quiz of this Question


  • Last Updated : 13 Nov, 2018

Share your thoughts in the comments