I want longest path from root to leaf. Then which code is correct among Code-1 or Code-2?
Code-1)
int tree(Struct node *root){
int a=0, b=0,c=0;
if(root==NULL)
return 0;
if((root->left==NULL)&&(root->right==NULL))
return 1;
a=1+tree(root->left);
b=1+tree(root->right);
c=1+max(a,b);
return c;
}
Code-2)
int tree(Struct node *root){
int a=0, b=0,c=0;
if(root==NULL)
return 0;
if((root->left==NULL)&&(root->right==NULL))
return 1;
a=tree(root->left);
b=tree(root->right);
c=1+max(a,b);
return c;
}