用链表存储输入的数字,要求存储的顺序与输入的顺序相反
1.记住分配空间啊!!!!
#include <stdio.h>
#include <stdlib.h>
typedef struct LNode
{
int data;
LNode *next;
}LNode;
void main()
{
LNode *L = NULL;
LNode *p = NULL;
int m;
int n;
scanf("%d",&n);
while(n--)
{
scanf("%d",&m);
p = (struct LNode*)malloc(sizeof(struct LNode));
p->data = m;
p->next = L;
L = p;
}
p = L;
while(p != NULL)
{
printf("%d\n",p->data);
p = p->next;
}
}