#define NULL 0 #define LEN sizeof(struct student) struct student { long num; struct student * next; }; int n; main() { struct student *head; struct student *p1,*p2,*p;
n=0;
p1=p2=(struct student *)malloc(LEN); scanf("%ld",&p1->num);/////// 这个地方为什么一定要输入数据呢? ?不输入成为一个空表也行啊? head=NULL; while(p1->num!=0) {n=n+1; if(n==1)head=p1; else p2->next=p1; p2=p1; p1=(struct student *)malloc(LEN); scanf("%ld",&p1->num); }
p2->next=NULL;
if(head!=NULL); p=head; do {printf("%ld\n",p->num); p=p->next; }while(p!=NULL); getch();
}
[此贴子已经被作者于2005-10-10 17:58:21编辑过]