Intersection point of 2 linked lists


for every input…it is showing -1 as output…whats wrong in my code???

For calculating the intersection point, the basic approach that you could follow is firstly to calculate the no of elements which are present in both linked list and then calculating the difference and making the pointer go to that position uptill there is difference, and making your pointer of a and b move uptil there data is different, and if at any point (a->data == b->data), that point will be treated as intersection point.

For ur reference, i am including the approach you could follow in the intersection code :https://ide.codingblocks.com/s/76558

while(temp!=NULL && temp2!=NULL)  //change
    {
        if(temp->data==temp2->data)
        {
            return temp->data;
        }
        temp=temp->next;
        temp2=temp2->next;
    }

for the obove code snipet should not we use the logic if(temp ==temp2) because the pointers should meet.data can be unequal in both the lists.