Why this code is showing segmentation fault? Please help


#1

int sym(TreeNode* A,TreeNode* B)
{
if(A->left==NULL&&A->right==NULL&&B->left==NULL&&B->right==NULL)
{
if(A->val==B->val) return 1;
else return 0;
}
if(sym(A->left,B->right)&&sym(A->right,B->left)) return 1;
else return 0;
}
int Solution::isSymmetric(TreeNode* A)
{
return sym(A->left,A->right);
}


#2

NULL checks missing in both the functions

MAIN - if(A == NULL) return true

RECURSIVE -
if(A == NULL && B == NULL) return true;
if(A == NULL ^ B == NULL) return false;