int createlink()
{
struct student
{
int data;
struct student *next;
};
struct student *head,*r;
r=head=(struct student *)malloc(sizeof(struct student));
if(head==NULL)
{
cout<<"内存分配不成功"<<endl;
return -1;
}
else
{
int m;
cout<<"请输入数组 0结束"<<endl;
while(cin>>m&&m!=0)
{
struct student * p;
p=(struct student *)malloc(sizeof(struct student));
if(p==NULL)
{
cout<<"分配内存不成功"<<endl;
return -1;
}
else
{
p->data=m;
p->next=NULL;
r->next=p;
r=r->next;
}
}
struct student * pp;
pp=head->next;
while(pp!=NULL)
{
cout<<pp->data<<endl;
pp=pp->next;
}
}
}
转载于:https://my.oschina.net/u/1446208/blog/384340