思路
链表为空和只有一个头结点不用反转
定义三个指针
1、第一个指针指向头结点的下一个的下一个结点
2、第二个指针指向第一个指针指向的下一个,用于遍历链表
3、第三个指针用于循环体中,完成头插操作
示例代码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Node
{
int data;
struct Node *next;
};
struct Node *link_init()
{
struct Node *head = (struct Node *)malloc(sizeof(struct Node));
if(head == NULL)
{
return NULL;