Please tell the problem with the code?

#include
using namespace std;
class node
{
public: int data;
node* next;
node(int data)
{
this->data=data;
next=NULL;
}
};
void insertAtTail(node* &head,int data)
{
node* temp=new node(data);
if(head==NULL)
{
head=temp;
}
else
{
node* trav=head;
while(trav->next!=NULL)
trav=trav->next;
trav->next=temp;
}
}
void print(node* head)
{
while(head!=NULL)
{
cout<data<<" ";
head=head->next;
}
}
void K_Append(node* &head,int n,int k)
{
if(k>=n)
return;
node* temp=head;
node* trav=head;
for(int i=1;i<(n-k);i++)
{
trav=trav->next;
}
head=trav->next;
trav->next=NULL;
node* trav2=head;
while(trav2->next!=NULL)
trav2=trav2->next;
trav2->next=temp;
}
int main()
{
node* head=NULL;
int n,k,value;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>value;
insertAtTail(head,value);
}
cin>>k;
K_Append(head,n,k);
print(head);
return 0;
}

share code in cb ide

@namangarg31
are u asking help for intersection of linked list
or k append linked list
because code is for intersection and u have refernced the doubt to k append

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.