#include<stdio.h>
#include<stdlib.h>
//给队列初始化
struct node
{
int data;
struct node*next;
};
//单节点插入链表函数
void Add(int x,struct node *ptail)
{
struct node *pnew=(struct node*)malloc(sizeof(struct node));
pnew->data=x;
ptail->next=pnew;
ptail=pnew;
ptail->next=NULL;
printf("成功插入一个节点\n");
}
int main()
{
struct node *head=(struct node*)malloc(sizeof(struct node));
struct node *ptail=(struct node*)malloc(sizeof(struct node));
head->next=ptail;
int x;
printf("请输入您需要插入的数字:\n");
scanf("%d",&x);
Add(x,ptail);
printf("%d",head->next->next->data);
return 0;
}
注意,这里的前两个节点是空节点