struct node* intersection( struct node *pL1, struct node* pL2)
{
   if ((!pL1) || (!pl2)) return NULL;
   struct node * pL3 = NULL;
   struct node* pL3Tail = NULL;
   while(pL1)&&(pL2) {
    if (pL1->data< pL2->data) pL1=pL1->next;
    else if  (pL1->data > pL2->data) pL2=pL2->next;
    else {
       struct node *pNew = (struct node*)malloc(sizeof(struct node));
       if !pNew return NULL; //scary
       pNew->data = pL1->data; pNew->next = NULL;
       if ( !pL3) pL3= pNew;
       else pL3Tail->next = pNew;
       pL3Tail = pNew;
   }
   return pL3;
}




}
Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652


On Wed, Jul 4, 2012 at 10:41 PM, Abhi <[email protected]> wrote:

> Any efficient algorithm to find intersection of two linked lists.Example:
> Linked List 1)  1 -> 2 -> 3 -> 4 -> 5 -> 6
> Linked List 2)  3 -> 4 -> 5
>
> Intersection 4 -> 5 -> 6
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/algogeeks/-/-8_lnGA-ZhgJ.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to