| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 440 人关注过本帖
标题:[求助]在链表中怎样建立读取函数?
只看楼主 加入收藏
晔非雪
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2006-9-16
收藏
 问题点数:0 回复次数:2 
[求助]在链表中怎样建立读取函数?

在链表中建立的读取函数运行时总是出错.

搜索更多相关主题的帖子: 链表 函数 
2006-09-19 15:29
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 

/*参照一下...*/

/*不带头结点的*/
typedef node* nodelink;

nodelink buildlink() /* 尾插法*/
{

datatype x;
nodelink head,s;
nodelink p2;
head=NULL;
p2=NULL;
printf("please input the link:");
scanf("%d",&x);
while(x!=0)
{s=(nodelink)malloc(sizeof(node));
s->info=x;
if (head==NULL) head=s; else p2->next=s;
p2=s;
scanf("%d",&x);
}
if(p2) p2->next=NULL;
return(head);
}

nodelink creatlink() /***头插法***/
{ nodelink head,p;
datatype x;
head=NULL;
printf("please input the link:");
scanf("%d",&x);
while(x!=0)
{ p=(nodelink)malloc(sizeof(node)) ;
p->info=x;
p->next=head;
head=p;
scanf("%d",&x);
}
return head;
}


倚天照海花无数,流水高山心自知。
2006-09-19 15:34
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 

/*带头结点的*/

typedef node* nodelink;

/* 头插法建立带头节点的单链表*/
nodelink tcreathlink()
{ datatype x;
node *head,*s;
head=(node*)malloc(sizeof(node));
printf("please input the datas:");
scanf("%d",&x);
while(x)
{ s=(node*)malloc(sizeof(node));
s->info=x;
s->next=head->next;
head->next=s;
scanf("%d",&x);
}
return head;
}
nodelink tbuildhlink() /*带头节点的尾插法*/
{

datatype x;
node *head,*s;
node *p2;
head=(node *)malloc(sizeof(node));
p2=head;
printf("please input the datas:");
scanf("%d",&x);
while(x!=0)
{s=(node *)malloc(sizeof(node));
s->info=x;
p2->next=s;
p2=s;
scanf("%d",&x);
}
if(p2) p2->next=NULL;
return(head);
}


倚天照海花无数,流水高山心自知。
2006-09-19 15:35
快速回复:[求助]在链表中怎样建立读取函数?
数据加载中...
 
   



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

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