code is not working when I am calling findcomm function
Intersection point two linked list(error)
Saksham, I have edited your code little bit… Also the approach you are trying to use in your findcomm function is not correct, Try using this approach which is explained in the video hint of this question as,
int intersection(node *a,node *b)
{
int len1=count_list(a);
int len2=count_list(b);
int diff;
if(len2>len1)
{
diff=len2-len1;
}
else
{
diff=len1-len2;
}
if(len2>len1)
{
for(int i=0;i<diff;i++)
{
b=b->next;
}
}
else
{
for(int i=0;i<diff;i++)
{
a=a->next;
}
}
while(a!=NULL && b!=NULL)
{
if(a->data!=b->data)
{
a=a->next;
b=b->next;
}
else if(a->data==b->data)
{
return a->data;
}
}
return -1;
}
This is the edited code… It is still giving runtime error because of findcomm function. So try to change that…