Please check the code ..why showing wrong ans;

#include
#include<bits/stdc++.h>
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;
}
node *tail=head;
while(tail->next!=NULL)
{
tail=tail->next;
}
tail->next=new node(data);

}
node* reverse(node* head, int k)
{
node * current =head;
node * prev=NULL;
node *n=NULL;
int c=0,cn=0;
node *temp=head;
while(temp)
{
cn++;
temp=temp->next;
}
if(cn<k)
{
return head;
}

    while(c<k && current!=NULL)
    {
        n=current->next;
        current->next=prev;
        prev=current;
        current=n;
        c++;
    }
    if(n!=NULL && c==k)
    {
        head->next=reverse(n,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;
for(int i=0;i<n;i++)
{
int d;
cin>>d;
insertattail(head,d);

 }
 

head=reverse(head,k);
print(head);
return 0;

}

@divisharoy14_5d0aa86c37c6588a, kindly share the code here bcoz when u send directly the code is not readable to us

@divisharoy14_5d0aa86c37c6588a if the doubt is still clear check here https://ide.codingblocks.com/s/658422

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.