One of the testcases is showing run error

#include
using namespace std;

class node{
public :
int data;
node* next;

node(int d) {
    data = d;
    next = NULL;
}

};

void insertathead( node*&head, int data){
if( head == NULL){
head = new node( data);
return;
}
noden = new node( data);
n->next = head;
head = n;
}
//printing the linked list.
void print(node
head){
while( head != NULL){
cout << head->data << " ";
head = head ->next;
}
cout << endl;
}

void reverse( node*&head){

node*c = head;
node*p = NULL;
while(c!= NULL){
    node*n = c->next;
    c->next = p;
    p = c;
    c = n;
   
}
 head = p;

}

nodeappend(node&head,int n, int k){
int cnt = 1;
node*a = head;

	while(cnt < n-k) {
		a = a->next;
		cnt++;
	}
	node*r = a->next;
	a->next = NULL;
	node*p = r;
	while( r->next!= NULL){
		r= r->next;
	}
	r->next = head;
	
	return p;

}

int main() {
int n;
cin >>n;
nodehead = NULL;
for( int i = 0; i <n; i++){
int no;
cin >>no;
insertathead(head,no);
}
reverse(head);
int k;
cin >>k;
node
c = append(head,n,k%n);
print©;
}

if k==n
in that case your code fails

handle that case explicitly in the append() function
like this
if(k==0)
return;