//L3_1.c

#include<stdio.h>
#include<stdlib.h>

//定义链表节点类型,这是C语言中非常经典的结构体
//但是这中定义有一点点难以理解struct node *next
//这应该是一种递归定义吧 ,定义一个结构体指针next

struct node
{
int d;
struct node *next;
};

void main()

{
int x;
struct node *head,*p,*q;
head =NULL; //将链表的头指针设为空
q=NULL;
scanf("%d",&x); //输入一个正整数

while(x>0) //如果输入的值大于0
{
p=malloc(sizeof(struct node)); //申请一个节点并分配内存
p->d=x; //设置当前节点数据域为输入的正整数x

//(*p).d=x
p->next=NULL; //设置当前的指针域为空
if (head==NULL) //若链表为空,则将头指针指向当前节点p
head=p;
else
q->next=p; //若链表不为空,则将当前节点链接在该链表的最后

q=p;
// printf(*q);
scanf("%d",&x);
}
p=head; //下面为打印一个链表
while(p!=NULL)
{
printf("%d\n",p->d);//输出当前节点的数据
q=p; //删除当前节点
p=p->next;

free(q); //释放删除的
}
return ;

}