Linked list append

sir why my code is satisfying only 1 test case im unable to figure out
please help
#include
using namespace std;
class node
{public:
int data;
node *next;
node(int d)
{
data=d;
next=NULL;
}

};
void inserttail(node *&head,long int d)
{node *n=new node(d);
if(head==NULL)
{head=n;
n->next=NULL;
return;}
node *temp=head;
while(temp->next!=NULL)
{temp=temp->next;
}
temp->next=n;
n->next=NULL;
return;}
void print(node *head)
{
while(head!=NULL)
{cout<data<<" ";
head=head->next;
}
}
int main()
{node *head=NULL;
long int n,a,k,z;
cin>>n;
for(long int i=0;i<n;i++)
{cin>>a;
inserttail(head,a);
}
cin>>k;
node *temp=head;
node *head2,*head3;
while(temp->next!=NULL)
{temp=temp->next;
}
temp->next=head;
node *temp2=head;
for(long int i=1;i<n-k;i++)
temp2=temp2->next;
head3=temp2->next;
temp2->next=NULL;
print(head3);
}

Hey Rahul, can you copy your code on ide, save it and share that link here, as the code you have copied here is giving so many compilation errors.

Hey Rahul, as you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.