#include<iostream>
#include <malloc.h>
using namespace std;
typedef int ElemType;
typedef struct LNode
{
ElemType data;
struct LNode *next;
}LNode,*LinkList;
void initList(LinkList &L)
{
L=(LinkList)malloc(sizeof(LNode));
L->next=NULL;
}
void creatList(LinkList &L,int n)
{
LinkList s,p;
s=L;
while(n--)
{
p=(LinkList)malloc(sizeof(LNode));
cin>>p->data;
p->next=s->next;
s->next=p;
}
}
void printList(LinkList &L)
{
if(L->next!=NULL)
printList(L->next);
cout<<L->data<<" ";
}
int main()
{
LinkList L;
initList(L);
int n;
cin>>n;
creatList(L,n);
printList(L);
}
不知道为什么总是会出现一个随机数在后面。