K-append link list

#include
using namespace std;
class node{
public:
int data;
node* next;
node(int d){
data=d;
next=NULL;
}
};
void insertattail(node*&head,int data){
if(head==NULL){
head=new node(data);
return;
}
nodetail=head;
while(tail->next!=NULL){
tail=tail->next;
}
tail->next= new node(data);
return ;
}
void buildlist(node
&head,int n){
int data;
int count=0;
while(count<n){
cin>>data;
insertattail(head,data);
count++;
} return;
}
void printlist(nodehead){
while(head!=NULL){
cout<data<<" ";
head=head->next;
}
cout<<endl;
}
int length(node
head){
int len=0;
while(head!=NULL){
head=head->next;
len+=1;
}
return len;
}
node append(node head, int k){
node *temp = head, t = head;
int i = -k;
while(temp->next!=NULL){
if(i>=0){
t = t->next;
}
temp = temp ->next;
i++;
}
temp->next = head;
head = t->next;
t->next = NULL;
return head;
}
int main() {
int n;
cin>>n;
node
head=NULL;
buildlist(head,n);
// printlist(head);
int k;
cin>>k;
head=append(head,k);
printlist(head);
}
whats wrong in this code?