当前位置: 代码迷 >> C语言 >> [求助]看看线性表那里有问题?????????
  详细解决方案

[求助]看看线性表那里有问题?????????

热度:275   发布时间:2007-05-14 22:21:41.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;
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  线性表  

----------------解决方案--------------------------------------------------------
struct student{
int number;
char name[8];
struct student *next;
}a[LA],b[LB];

到底是线性表的链式存储还是顺序存储.
----------------解决方案--------------------------------------------------------
两个链表a,b.从a链表中删除b链表中有相同的学号..
----------------解决方案--------------------------------------------------------
#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编辑过]


----------------解决方案--------------------------------------------------------
[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]
还有这样回事!!!!!!!!!
谢谢了!!!!!!!
----------------解决方案--------------------------------------------------------
  相关解决方案