Reputation: 23
I got the output for below code but i am not getting the exact logic.
Line 3(recursive fn call) will pass the value Null
when it reaches leaf node , then how can it print the data part
void Inorder(struct node *node)
{
if(node!=NULL)
{
Inorder(node->left);
printf("%d",node->data);
Inorder(node->right);
}
}
Upvotes: 2
Views: 46
Reputation: 7602
Basically at every recursive call you continue if the node is not null.
Hence the call node->left
for the leaf node would not continue further and the nodes get printed in the next line as the recursive function unfolds.
Dry run an example and verify for yourself.
Upvotes: 2