小编Ama*_*nda的帖子

函数中的分段错误以反转单链表recursivley

我正在实现一个递归反转链表的函数,但是遇到了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.

谢谢你们 :)

c recursion linked-list segmentation-fault data-structures

2
推荐指数
1
解决办法
702
查看次数