#include<stdio.h>
#include<stdlib.h>
typedef struct stu
{int num;
char name[20];
struct stu *next;
}student;
inits (student *head)
{head=(student*)malloc(sizeof(student));
if(head!=NULL)
printf("开辟成功");
else printf("开辟失败");
}
creat(student *head)
{student *p,*q;
p=head;
do
{q=(student *)malloc(sizeof(student));
scanf("%d %s",&q->num,q->name);
p->next=q;
q->next=NULL;
p=q;
}while(p->num>0);
}
shuchu(student *head)
{student *p;
for(p=head;p->num>0;p=p->next)
printf("%d %s",p->num,p->name);
}
main()
{student *head,tou;
head=&tou;
inits (head);
creat(head);
shuchu(head);
}
#include<stdlib.h>
typedef struct stu
{int num;
char name[20];
struct stu *next;
}student;
inits (student *head)
{head=(student*)malloc(sizeof(student));
if(head!=NULL)
printf("开辟成功");
else printf("开辟失败");
}
creat(student *head)
{student *p,*q;
p=head;
do
{q=(student *)malloc(sizeof(student));
scanf("%d %s",&q->num,q->name);
p->next=q;
q->next=NULL;
p=q;
}while(p->num>0);
}
shuchu(student *head)
{student *p;
for(p=head;p->num>0;p=p->next)
printf("%d %s",p->num,p->name);
}
main()
{student *head,tou;
head=&tou;
inits (head);
creat(head);
shuchu(head);
}