我正在实现一个递归反转链表的函数,但是遇到了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;
}
Run Code Online (Sandbox Code Playgroud)
你能帮忙吗?
PS迭代版本工作正常.它不是功课.只是练习C.
谢谢你们 :)