#include<stdio.h>
#include<stdlib.h>
//这个代码里面,我没有将链表L的指针next,指向下一个地址,为什么程序没出错,可以正常输出呢?
typedef struct LNode
{
int data;
struct LNode *next;
} LinkList,LNode;
LinkList *CreateList()
{
LinkList *head ,*L,*tail;
head=NULL;
tail=NULL;
int n;
printf("请输入函数的个数:\n");
scanf("%d",&n);
printf("请输入%d个元素\n",n);
int i;
for(i=n;i>=1;i--)
{
L=(LinkList*)malloc(sizeof(LNode));
if(head==NULL)
head=L;
else
tail->next=L;
scanf("%d",&L->data);
L->next=NULL;
tail=L;
}
L=head;
return head;
}
void PrintList_L(LinkList *L)
{
LinkList *p;
p=L;
while(p)
{
printf("%d ",p->data);
p=p->next;
}
printf("\n");
}
int main()
{
LinkList *L;
L=CreateList();
PrintList_L(L);
}