慕用4063026
#include <iostream>
#include"malloc.h"
using namespace std;
struct LinkList
{
int data;
LinkList *next;
};
void CreateList_L(LinkList *&L,int n)
{
int i;
LinkList *p;
L=(LinkList*)malloc(1);
L->next=NULL; //这句话要加,否则最后会出错。结尾不为NULL,就没办法判断结束
for (i=n;i>0;--i)
{
p=(LinkList*)malloc(1);
scanf("%d",&p->data);
p->next = L->next;
L->next = p;
}
}
int main()
{
LinkList *head;
CreateList_L(head,5);
LinkList *p=head->next;
while(p!=NULL)
{
cout<<p->data<<" ";
p=p->next;
}
return 0;
}