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;
}