Alternate solution-is this code also correct?

int sum(node*root)
{ if(root==NULL)
return 0;
root->data=root->data+sum(root->left)+sum(root->right);
return root->data+sum(root->left)+sum(root->right):
}

MY DOUBT HAS’NT BEEN RESOLVED,AND I DON’T KNOW HOW THIS DOUBT APPEARED IN THE RESOLVED SECTION?

hey @pradyumn2006, root data should include data of both its child only and it should pass data of its own and data of its children to upper node.
it should be like that

int sum(node*root)
{ if(root==NULL)
return 0;
int temp=root->data;
root->data=sum(root->left)+sum(root->right);
return temp+root->data
}

If your not able to understand this, just dry run your code and this code once.