Ll k append not working properly

my code is not working fine can u plz suggest
here is the link

@ayush1213
Your approach seems wrong. There is no need to reverse any part of the linked list and I don’t really understand why you are doing it. Also recursion is not required for this problem. This is a pretty straightforward problem.
Say there are n elements in your list. Just go to (n-k) th element . Store its next in a temp variable. Make the next of current element as NULL as this would be the new end of our linked list. Now join the next pointer of the last element of the linked list starting with temp to our previous head pointer. This should do it.

@tarunluthra sry i falsely put the title it is ll k reverse

@ayush1213
Add this statement after the reversing loop
c->next = p;

1 Like

tq very much sir helped a lot

@ayush1213
Kindly mark this doubt as resolved if your issue is solved.

1 Like