#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编辑过]
----------------解决方案--------------------------------------------------------
不输入数据给N的话,N的值会一直是你第一次输入时的数据,如果第一次给N输入非零数,那么就不会跳出while成为死循环
----------------解决方案--------------------------------------------------------
定一下 希望能得到帮助
----------------解决方案--------------------------------------------------------
ding
----------------解决方案--------------------------------------------------------
不输入数据给N的话,N的值会一直是你第一次输入时的数据,如果第一次给N输入非零数,那么就不会跳出while成为死循环
是这样的吗?while语句里面不是有输入语句吗,不会死循环的吧!我认为在while前面输入值只是为了初始话p->num的值而已,从而进入循环或不进入循环
----------------解决方案--------------------------------------------------------