What is the error?

void display(node* root)
{
if(root==NULL)
{
cout<<“END”;
return;
}
cout<<(root->left)->data<<" => “<data<<” <== "<<(root->right)->data;
display(root->left);
display(root->right);
}
Can u please tell what’s wrong with this code?

Hello @Hk199977,

The following statement will produce a run-time error for the nodes with either 1 child or no child:
cout<<(root->left)->data<<" => “<data<<” <== "<<(root->right)->data;

Solution:
First, check if it’s left and right child exists or not.
If it does,
then print it.

Following is the correct implementation of the display function:

Hope, this would help.
Give a like if you are satisfied.

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.