157. How to find whether two link-lists intersect each other or not? ......
Microsoft Interview Questions and Answers
(Continued from previous question...)
157. How to find whether two link-lists intersect each other or not? ......
Question:
How to find whether two link-lists intersect each other or not?
If yes find intersection point.
maybe an answer:
int check( struct node * list1,struct node * list2)
{
int count1 = countLL(list1);
int count2 = countLL(list2);
while(count1> count2)
{
list1 = list1->next;
count1--;
}
while(count2>count1)
{
list2 = list2->next;
count2--;
}
while(list1 ! = list2)
{
list1 = list1->next;
list2 = list2->next;
}
if(list1== null)
{
return 0;/ do not intersect
}
else
return 1; //it intersects
}
(Continued on next question...)
Other Interview Questions
|