标题:链表确实有很多问题
取消只看楼主
Pallove
Rank: 1
等 级:新手上路
帖 子:62
专家分:0
注 册:2006-3-26
 问题点数:0 回复次数:0 
链表确实有很多问题

下面的这个链表为什么老是不对呢,哪个大虾能帮帮我行吗
#include "stdio.h"
#include "malloc.h"
#define LEN sizeof(struct stud)
struct stud
{
int num;
float scores;
struct stud *next;
};
main()
{
struct stud *head,*p1,*p2;
int n=0;
p1=p2=(struct stud *)malloc(LEN);
scanf("num=%d,scores=%f",&p1->num,&p1->scores);
head=NULL;
while(p1->num!=0)
{
n++;
if (n==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(struct stud *)malloc(LEN);
scanf("num=%d,scores=%f",&p1->num,&p1->scores);
}
p2->next=NULL;
p2=head;
while(p2->next!=NULL)
{
printf("num=%d scores=%f",p2->num,p2->scores);
p2=p2->next;
}

getch();
}

搜索更多相关主题的帖子: 链表 
2006-04-06 14:02



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-55527-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.377090 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved