相关疑难解决方法(0)

在c中递归地反转链表

当head作为参数发送给它时,以下代码可以正常工作.由于我是C的新手,我无法理解它是如何工作的.请帮帮我.

struct node *recursiveReverseLL(struct node *list)
{
    struct node *revHead;
    if (list == NULL || list->link == NULL)
    {
        return list;
    }

    revHead = recursiveReverseLL(list->link);
    list->link->link = list;
    list->link = NULL; 

    return revHead;
}
Run Code Online (Sandbox Code Playgroud)

我不知道如何使用这些递归调用提供链接.即)如果链接为,

1 -> 2 -> 3 -> 4 
Run Code Online (Sandbox Code Playgroud)

然后hw被改变为,

4 -> 3 -> 2 -> 1
Run Code Online (Sandbox Code Playgroud)

c recursion linked-list singly-linked-list

16
推荐指数
2
解决办法
6万
查看次数

标签 统计

c ×1

linked-list ×1

recursion ×1

singly-linked-list ×1