【发布时间】:2011-12-19 06:46:42
【问题描述】:
我在链表中定义了一个节点:
typedef struct abc
{
int id;
struct abc *next;
}node;
我想递归地反转链接列表。我将头指针传递给函数。我的函数定义如下:
node *reverseLinkedListRecursively(node *head)
{
node *current;
node *rest;
if(head == NULL)
return head;
current=head;
rest=head->next;
if(rest == NULL)
{
return rest;
}
reverseLinkedListRecursively(rest);
current->next->next=rest;
current->next=NULL;
return rest;
}
我应该如何进行?我已经实现了迭代方法。
【问题讨论】:
-
这是作业吗?它看起来像家庭作业。如果您希望别人帮助您,那么您应该表明您至少尝试过自己解决问题。
标签: c linked-list