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 first;
NodeP rest = recursiveReverseList(first->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.
Thank you all :)