Google
 
资源下载 | 发布源码资源

已解决问题
这个生成链表的函数有什麼问题??
 
问题补充: p1重复开空间是什麼意思??还是这段代码有错?? struct student *creat() /*返回一个指向链表头的指针*/ { struct student *head; struct student *p1, *p2; n=0; p1=(struct student*)malloc(LEN); p2=(struct student*)malloc(LEN); /*开辟一个新单元*/ scanf("%d %f",&p1->num,&p1->score); 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("%d %f",&p1->num,&p1->score); } p2->next=NULL; return(head); }
提问者:tomore  提问时间:08-10-20 20:29  
 最佳答案
 的答案  ( 采纳时间: 70-01-01 08:00 )

 评论  回答时间: 70-01-01 08:00 
其他答案 (1)

p1=(struct student*)malloc(LEN); p2=(struct student*)malloc(LEN); /*开辟一个新单元*/ 这里改成下面的 p2=p1=(struct student*)malloc(LEN); //使P1P2同指向第一个节点 这样下面的那些构造链表的时候的指针才能对应,才能顺利构造链表- -|| 改了就没问题了
0 评论  回答时间: 1224510812 


关于我们 - 广告服务 - 联系我们 - 网站声明 - Archiver - WAP - TOP
Copyright (c) 2001-2010 kkbar.com. All rights reserved.  京ICP备10020589号