| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 561 人关注过本帖
标题:关于链表的,帮我看看那里错误
只看楼主 加入收藏
dreamhouse
Rank: 1
等 级:新手上路
帖 子:107
专家分:7
注 册:2011-12-16
结帖率:59.46%
收藏
已结贴  问题点数:2 回复次数:3 
关于链表的,帮我看看那里错误
#include<stdio.h>
#include<stdlib.h>
struct student
{
    long num;
    float score;
    struct student * next;
};
int n=0;//结点的个数
struct student * creat(void)
{
    struct student * head;
    struct student * p;
    struct student * tail;
    head=NULL;
    p=(struct student *)malloc(sizeof(struct student));//开辟一个结点
    scanf("%ld %f",&p->num,&p->score);
    while(p->num!=0)
        if(head==NULL)
            head=p;//指向新的结点
            //作为表尾的结点(最后的结点)
        else
        tail->next=p;//当前的最后一个结点指向新生成的结点
        
        tail=p;
    p=(struct student *)malloc(sizeof(struct student));
    scanf("%ld %f",&p->num,&p->score);
}
return head;
}
main(){
   struct student * head=create();
   struct student * p=head;
   while(p!=NULL)
   {
      printf("node[num=%ld,score=%f]\n",p->num,p->score);
      p=p->next;
      }
   return 0;
}
搜索更多相关主题的帖子: include 看看 
2013-06-03 16:36
q13678986740
Rank: 4
等 级:业余侠客
帖 子:114
专家分:245
注 册:2012-7-7
收藏
得分:2 
你创建链表时没有在链表尾指向Null
2013-06-03 23:48
dreamhouse
Rank: 1
等 级:新手上路
帖 子:107
专家分:7
注 册:2011-12-16
收藏
得分:0 
回复 2楼 q13678986740
谢谢

vvvvvvvvvv
2013-06-24 10:58
快速回复:关于链表的,帮我看看那里错误
数据加载中...
 
   



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

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