How this program works, Explain and also diagrammatically illustrate. void Childs(node *root,char D) { if(root==NULL) { return; } if(root->data==D) { if(root->left!=NULL&&root->right!=NULL) { cout<data<<" is the father of : "; cout<left->data<<" and "<right->data<left==NULL&&root->right!=NULL) { cout<data<<" has only one child i.e. : "; cout<right->data<left!=NULL&&root->right==NULL) { cout<data<<" has only one child i.e. : "; cout<left->data<data<<" Has No Child\n"; return; } } Childs(root->left,D); Childs(root->right,D); }
How this
void Childs(node *root,char D)
{
if(root==NULL)
{
return;
}
if(root->data==D)
{
if(root->left!=NULL&&root->right!=NULL)
{
cout<<root->data<<" is the father of : ";
cout<<root->left->data<<" and "<<root->right->data<<endl;
return;
}
else if(root->left==NULL&&root->right!=NULL)
{
cout<<root->data<<" has only one child i.e. : ";
cout<<root->right->data<<endl;
return;
}
else if(root->left!=NULL&&root->right==NULL)
{
cout<<root->data<<" has only one child i.e. : ";
cout<<root->left->data<<endl;
}
else
{
cout<<root->data<<" Has No Child\n";
return;
}
}
Childs(root->left,D);
Childs(root->right,D);
}
Step by step
Solved in 3 steps with 2 images