Please help…Segmentation Fault(Core Dumped) is being shown by the compiler.Please rectify my code and tell me my mistakes in the code
Code:https://ide.codingblocks.com/s/226604
Largest BST In A Binary Tree
Hey @GreatCoderboy123
in line no 79:
int j=max(countnodes(root->left),countnodes(root->right));
you can’t call countnodes on root->right or root->left if root is NULL, so before calling check that root is not null
I tried the suggestion by imposing an if statement before line 79:
int j;
if(root!=NULL)
{
j=max(countnodes(root->left),countnodes(root->right));
}
But it is giving 19 segmentation fault and that too core dumped
@GreatCoderboy123
do it like:
int lc = 0, rc = 0;
if(root != NULL) {
lc = countnodes(root->left);
rc = countnodes(root->right);
}
int j = max(lc, rc);
it won’t give segmentation error now.
I tried the same but it is still giving segmentation fault 17 (core dumped)
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.