Im getting wrong o/p in this code check once
your reverse function is not correct
not passing even sample testcases
look at this fucntion below
you have to do like that
node* reverse(node* head, int k) {
if(head==NULL)return NULL;
node* curr=head;
node* prev=NULL;
node* nxt=curr->next;
int cnt=0;
while(cnt<k&&curr){
curr->next=prev;
prev=curr;
curr=nxt;
if(curr)nxt=curr->next;
cnt++;
}
head->next=reverse(curr,k);
return prev;
}
your approach is similar to this but there are some mistakes and dont handle corner cases
even the code you sent is giving the same o/p as mine , make required change in this code https://ide.codingblocks.com/s/313333
actually the problem is in main()
you are not updating the head in main()
head=reverseg(head,k);
this is correct statement at line no 68 in your code
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.