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

#include<stdio.h>
#include<string.h>
#define LA 4
#define LB 5
struct student{
int number;
char name[8];
struct student *next;
}a[LA],b[LB];
void main(){

struct student a[LA]={{101,"wang"},{102,"li"},{105,"zhang"},{106,"
wei"}};
struct student b[LB]={{103,"zhang"},{104,"ma"},{105,"chen"},{107,"
guo"},{108,"lui"}};
int i;
struct student *p,*p1,*p2,*head,*head1;
head=a;
head1=b;
printf("list A:\n");
for(p1=head,i=1;i<=LA;i++){
if(i<LA) p1->next=a+i;
else p1->next=NULL;
printf("%4d%8s\n",p1->number,p1->name);
if(i<LA) p1=p1->next;
}
printf("\nlist B:\n");
for(p2=head1,i=1;i<=LB;i++){
if(i<LB) p2->next=b+i;
else p2->NULL;
printf("%4d%8s\n",p2->number,p2->name);
if(i<LB) p2=p2->next;
}
/*a链表进行删除操作*/
p1=head;
while(p1!=NULL)
{p2=head1;
while((p1->number!=p2->number)&&(p2->next!=NULL))
p2=p2->next;
if(p1->number==p2->number)
if(p1==head)
head=p1->next;
else
{
p->next=p1->next;
p1=p1->next;
}
else
{p=p1;p1=p1->next;}
}
printf("\nresult:\n");
p1=head;
while(p1!=NULL){
printf("%4d%8s",p1->number,p1->name);
p1=p1->next;
}
}


搜索更多相关主题的帖子: head 103 include number 线性表 
2007-05-14 22:21
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 
struct student{
int number;
char name[8];
struct student *next;
}a[LA],b[LB];

到底是线性表的链式存储还是顺序存储.

倚天照海花无数,流水高山心自知。
2007-05-14 22:27
子阳
Rank: 1
等 级:新手上路
帖 子:71
专家分:0
注 册:2007-3-5
收藏
得分:0 
两个链表a,b.从a链表中删除b链表中有相同的学号..
2007-05-14 22:31
YOGIOH
Rank: 1
等 级:新手上路
帖 子:102
专家分:0
注 册:2007-5-8
收藏
得分:0 
#include<stdio.h>
#include<string.h>
#define LA 4
#define LB 5
struct student{
int number;
char name[8];
struct student *next;
}a[LA],b[LB];
void main(){

struct student a[LA]={{101,"wang"},{102,"li"},{105,"zhang"},{106,"wei"}};//我这里编译说不能换行
struct student b[LB]={{103,"zhang"},{104,"ma"},{105,"chen"},{107,"guo"},{108,"lui"}};//同理
int i;
struct student *p,*p1,*p2,*head,*head1;
head=a;
head1=b;
printf("list A:\n");
for(p1=head,i=1;i<=LA;i++){
if(i<LA) p1->next=a+i;
else p1->next=NULL;//少个NEXT=
printf("%4d%8s\n",p1->number,p1->name);
if(i<LA) p1=p1->next;
}
printf("\nlist B:\n");
for(p2=head1,i=1;i<=LB;i++){
if(i<LB) p2->next=b+i;
else p2->next=NULL;
printf("%4d%8s\n",p2->number,p2->name);
if(i<LB) p2=p2->next;
}
/*a链表进行删除操作*/
p1=head;
while(p1!=NULL)
{p2=head1;
while((p1->number!=p2->number)&&(p2->next!=NULL))
p2=p2->next;
if(p1->number==p2->number)
if(p1==head)
head=p1->next;
else
{
p->next=p1->next;
p1=p1->next;
}
else
{p=p1;p1=p1->next;}
}
printf("\nresult:\n");
p1=head;
while(p1!=NULL){
printf("%4d%8s",p1->number,p1->name);
p1=p1->next;
}
getch();
}

[此贴子已经被作者于2007-5-14 22:50:11编辑过]


2007-05-14 22:38
子阳
Rank: 1
等 级:新手上路
帖 子:71
专家分:0
注 册:2007-3-5
收藏
得分:0 
[QUOTE]struct student a[LA]={{101,"wang"},{102,"li"},{105,"zhang"},{106,"wei"}};//我这里编译说不能换行
struct student b[LB]={{103,"zhang"},{104,"ma"},{105,"chen"},{107,"guo"},{108,"lui"}};//同理
[/QUOTE]
还有这样回事!!!!!!!!!
谢谢了!!!!!!!
2007-05-14 22:47
快速回复:[求助]看看线性表那里有问题?????????
数据加载中...
 
   



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

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