recursively reverse linked list.

Posted by Amanda on Stack Overflow See other posts from Stack Overflow or by Amanda
Published on 2010-04-12T09:48:41Z Indexed on 2010/04/12 9:53 UTC
Read the original article Hit count: 198

Filed under:
|
|

I am implementing a function to recursively reverse a linked-list, but getting seg-fault.

typedef struct _node {
   int data;
   struct _node *next;
} Node, *NodeP;

NodeP recursiveReverseList(NodeP first){
   if(first == NULL) return NULL;
   if(first->next == NULL) return head;

   NodeP rest = recursiveReverseList(head->next);
   rest->next = first;
   first->next = NULL;

   return first;
}

Can you please help.

P.S. The iterative version is working fine though. Its not homework. Just practicing C.

© Stack Overflow or respective owner

Related posts about c

    Related posts about recursion