my program is not working
#include
using namespace std;
class node{
public:
int data;
node * next;
node(int d)
{
data=d;
next=NULL;
}
};
void print (node*head)
{
while(head!=NULL)
{
cout<data<<" “;
head=head->next;
}
cout<<”\n";
}
void insertathead(node *&head,int data)
{
node * n= new node(data);
n->next=head;
head=n;
}
void insertattail(node *&head,int data)
{
if(head==NULL){
head= new node(data);
return;
}
node * temp=head;
while(temp->next!=NULL)
temp=temp->next;
temp->next=new node (data);
return;
}
void insertlist(node *& head,int s)
{
int data,i=0;
cin>>data;
while(i<s)
{
insertattail(head,data);
cin>>data;
i++;
}
}
ostream & operator<<(ostream & os,node *&head)
{
print(head);
return os;
}
void reverse (node *& head,node * p,int k)
{
if(p->next==NULL)
return;
node * c=p->next;
node * n;
node* f=p;
node* l;
if(f==NULL)
c=head;
for(int i=0;i<k;i++)
{
n=c->next;
c->next=p;
p=c;
c=n;
}
l=c;
if(f!=NULL)
f->next=p;
else
head=p;
node * temp=f;
for(int i=0;i<k;i++)
{
temp=temp->next;
}
temp->next=l;
reverse(head,temp,k);
}
int main()
{
int s,k;
cin>>s>>k;
node * head=NULL;
insertlist(head,s);
cout<<head;
reverse(head,NULL,k);
cout<<head;
return 0;
}