Getting segmentation fault on diameter

int diameter(node* root)
{
if(root=NULL)
{
return 0;
}
int h1=height(root->left);
int h2=height(root->right);
int d1=h1+h2;
int d2=diameter(root->left);
int d3=diameter(root->right);
return max(d1,max(d2,d3));
}
int main()
{
node* root=buildTree();
/printPreOrder(root);
cout<<"\n";
printInOrder(root);
cout<<"\n";
printPostOrder(root);
cout<<"\n";
/
// cout<<height(root)<<"\n";
// printingAllLevel(root);
// cout<<"\n";
//bfs(root);
//cout<<count(root)<<"\n";
//cout<<sum(root)<<"\n";
cout<<diameter(root)<<"\n";

return 0;

}

Hey @vbelwal73
in the third line
it has to be if(root == NULL) instead of if(root = NULL).
try this, if still facing errors, post your complete code(which has code of the height function also).

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.