Reversec linked list of given size of k

what is wrong in this code why it is not running ??
Please help me with this !!

#include
using namespace std;

class Node{

public:
	int data;
	Node *next;

};

void insertAtHead(Node *&head,int data){
Node *n =new Node;
n->data =data;
n->next=head;
head=n;
}

void insertAtTail(Node *&head, int data){

Node *tail =head;
while(tail->next !=NULL){
	tail = tail ->next;
}
tail->data= data;
tail->next=NULL;

}

Node *reverse (Node *head,int k){
Node *current=head;
Node *next=NULL;
Node *prev=NULL;
int count =0;

while(count < k && current !=NULL){
	next = current->next;
	current->next=prev;

	prev = current;
	current=next;
	count++;
}
if(next != NULL){
	head->next= reverse(next,k);
}
return prev;

}

void print(Node *head){
while(head !=NULL){
cout<data<<" ";
head=head->next;
}
}

int main(){

Node *head =NULL;
int n,k;
cin>>n>>k;


while(n>0){
	int data;
	cin>>data;
	insertAtTail(head,data);
	
	n--;
}
Node *prev;
prev = reverse(head,k);
print(prev);

return 0;

}

@neelmani98 hey do k=k%length of ll at starting ,rest your logic is looking correct.

there is something error in while loop which is present in main method to take input as I am inputting 8, 8 the value of n and k and after entering linked list data but after just entering 2 the programme exits

@neelmani98 hey apke input me galti hai ,usethis logic to take input,maintain two pointers head and last and take input of data and make node and attach that node to next of last and update last.