i am trying to learn tree with C. i need to find longest path. i am using recursive approach for this. but i am getting segmentation fault. i am not able to find why it is happening. i dont need logic. i want to do it on my own. just want to know what basic fault I am doing.
Any suggestion for handling pointers is most welcome.
void longestPath(struct node *p,int *maxlen,int count)
{
if(p==NULL)
return;
count++;
if(p->lft==NULL && p->rt==NULL )
{
if(*maxlen<count)
*maxlen=count;
}
longestPath(p->lft,maxlen,count);
longestPath(p->rt,maxlen,count);
}
||instead of&&.p->lft==NULL && p->rt==NULLbep->lft==NULL || p->rt==NULL?NULL.