| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 492 人关注过本帖
标题:[求助]关于链表
只看楼主 加入收藏
city505
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2005-11-5
收藏
 问题点数:0 回复次数:3 
[求助]关于链表

请教一个问题,为什么它显示最后输入的数.有什么办法能全部显示出来!
我采用的是链式!
#include <stdio.h>
#include <stdlib.h>
creat();
output();
struct shuju
{
int a;
struct shuju *next;
};
struct shuju *h;
main()
{
int i;
h=NULL;
for(i=0;i<5;i++)
creat();
output();
}
creat()
{
struct shuju *q,*t;
q=(struct shuju *)malloc(sizeof(struct shuju));
q->next=NULL;
t=q;
if(h==NULL)
{
h=t=q;
printf("nter data to a:");
scanf("%d",&t->a);
}
else
{
t->next=q;
t=q;
printf("enter data to a:");
scanf("%d",&t->a);
}
}
output()
{
struct shuju *q;
q=(struct shuju *)malloc(sizeof(struct shuju));
q=h;
while(q)
{
printf("%5d",q->a);
q=q->next;
}

}

搜索更多相关主题的帖子: 链表 
2006-02-22 22:05
aiyuheng
Rank: 1
等 级:新手上路
威 望:1
帖 子:656
专家分:0
注 册:2006-1-12
收藏
得分:0 
你没有返回头指针啊

when i want to ask anyone,i will ask myself first.
2006-02-22 23:25
aiyuheng
Rank: 1
等 级:新手上路
威 望:1
帖 子:656
专家分:0
注 册:2006-1-12
收藏
得分:0 
链表建的有问题

when i want to ask anyone,i will ask myself first.
2006-02-22 23:26
khhily
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2006-2-20
收藏
得分:0 

#include <stdio.h>
#include <stdlib.h>
*creat();
output(struct shuju *s);
struct shuju
{
int a;
struct shuju *next;
};
struct shuju *h;
main()
{
int i;
h=NULL;
for(i=0;i<5;i++)
creat();
output(h);
}
*creat()
{
struct shuju *q,*t;
q=(struct shuju *)malloc(sizeof(struct shuju));
scanf("%d",&q->a);
q->next=NULL;
t=q;
while(a!=0)
{
if(h==NULL)
h=t=q;
else
t->next=q;
t=q;
q=(struct shuju *)malloc(sizeof(struct shuju));
scanf("%d",&q->a);
}
t->next=NULL;

return h;
}
output(struct shuju *s)
{
struct shuju *q;
q=(struct shuju *)malloc(sizeof(struct shuju));
q=s;
while(q!==NULL)
{
printf("%5d",q->a);
q=q->next;
}

}

应该是这样子吧,
我也是才学不久,错了不要骂我哈

[此贴子已经被作者于2006-2-23 17:48:35编辑过]


2006-02-23 17:46
快速回复:[求助]关于链表
数据加载中...
 
   



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

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