I am getting error in this code
Intersection point two linked lists
Mukul pls share your code by saving on ide so that I could check the error
#include
using namespace std;
class node{
public:
int data;
node* next;
node(int d){
data = d;
next = NULL;
}
};
/*
int intersection(nodehead1,nodehead2)
{
while(head1!=NULL||head2!=NULL)
{
if(head1->data==head2->data)
{
return head1->data;
}
head1=head1->next;
head2=head2->next;
}
return -1;
}/
void print(nodehead){
while(head!=NULL){
cout<<head->data<<" ";
head = head->next;
}
cout<<endl;
}
void insertAtTail(node*&head,int data){
if(head==NULL){
head = new node(data);
return;
}
node*tail = head;
while(tail->next!=NULL){
tail = tail->next;
}
tail->next = new node(data);
return;
}
int main() {
int t=1;
while(t!=0)
{
nodehead1=NULL;
nodehead2=NULL;
int n1,a,n2,b;
cin>>n1;
for(int i=0;i<n1;i++)
{
cin>>a;
insertAtTail(head1,a);
}
cin>>n2;
for(int i=0;i<n2;i++)
{
cin>>b;
insertAtTail(head2,b);
}
while(head1!=NULL||head2!=NULL)
{
if(head1->data==head2->data)
{
cout<data;
break;
}
head1=head1->next;
head2=head2->next;
}
if(head1!=NULL||head2!=NULL)
{
cout<<"-1";
}
t–;
}
return 0;
}