一、示例

二、上代码
#include <stdio.h>
#include <stdlib.h>
// 定义节点结构体
struct Node {
int val;
struct Node* next;
};
// 定义链表结构体
struct LinkedList {
struct Node* head;
struct Node* tail;
int length;
};
// 递归法翻转链表
struct Node* reverseLinkedList(struct Node* head) {
// 如果链表为空或只有一个节点,直接返回该节点
if (head == NULL || head->next == NULL) {
return head;
}
// 递归翻转链表的其余部分
struct Node


1万+

被折叠的 条评论
为什么被折叠?



