Reversing linked list C

Posted by user2976389 on Stack Overflow See other posts from Stack Overflow or by user2976389
Published on 2014-06-13T03:14:32Z Indexed on 2014/06/13 3:24 UTC
Read the original article Hit count: 82

Filed under:
|
node *rever(node *root)
{
node *prev = NULL;
node *xnew = NULL;

  while (root != NULL) {

  xnew = malloc(sizeof(root));
  xnew->value = root->value;
  xnew->next = prev;

  prev = xnew;
  root = root->next;
  }



  return xnew;
}

Hello I wrote this linked list reverse function. However it doesn't work(empty response): I suspect it's because of prev index getting overwritten. Could someone explain me whats going on? I know I could find working code on the internet but I wanna know what am I doing wrong.

Thanks

© Stack Overflow or respective owner

Related posts about c

    Related posts about linked-list