Linked list k reverse

what is wrong with the code,its not working correctly on first k elements while it works fine on next k’s.

there were two errors

  1. at line 28, instead of head->next = reverse(next, k); it should be head->next = reverse(current, k);
  2. at line 65, instead of directly calling reverse(head,k) you should have done head=reverse(head,k)
    as the reverse function returns the head of reversed list so head in your main function should be updated as well

I have updated your code : https://ide.codingblocks.com/s/182544

1 Like