Sei sulla pagina 1di 1

/* The structure of the Linked list Node is as follows:

struct node {
int val;
struct node* next;
}; */
void intersection(struct node **head1, struct node **head2, struct node **head3)
{
// Your Code Here
struct node *t1=*head1,*t2=*head2;
*head3=NULL;
struct node *t3=*head3;
int a[30],i=0;
while(t1!=NULL)
{
while(t2!=NULL)
{
if(t1->val==t2->val)
{
a[i]=t1->val;
i++;
break;
}
else
t2=t2->next;
}
t1=t1->next;
}
i=i-1;
if(*head3==NULL)
{
t3=new node();
t3->val=a[i];
t3->next=NULL;
*head3=t3;
i--;
}
while(i>=0)
{
t3=new node();
t3->val=a[i];
t3->next=*head3;
*head3=t3;
i--;
}
}

Potrebbero piacerti anche