文档库 最新最全的文档下载
当前位置:文档库 › 集合的交、并、差的运算 数据结构课程设计代码

集合的交、并、差的运算 数据结构课程设计代码

#include
#include

typedef struct pointer{
char data;
struct pointer *link;
} pointer;

void readdata(pointer *head){ /*???*/
pointer *p;

char tmp;
printf("input data ('0' for end),the letter is lower!\n");
scanf("%c",&tmp);
while(tmp != '0')
{
p=(pointer *)malloc(sizeof(struct pointer));
p->data=tmp;
p->link=head->link;
head->link=p;
scanf("%c",&tmp);
}
}

void disp(pointer *head){ /*??????*/
pointer *p;
p=head->link;
while(p!=NULL)
{
printf("%c ",p->data);
p=p->link;
}
}

void bing(pointer *head1,pointer *head2, pointer *head3){ /*????1???2??*/
pointer *p1,*p2,*p3;
p1=head1->link;
while(p1!=NULL)
{
p3=(pointer *)malloc(sizeof(struct pointer));
p3->data=p1->data;
p3->link=head3->link;
head3->link=p3;
p1=p1->link;
}
p2=head2->link;
while(p2!=NULL)
{
p1=head1->link;
while((p1!=NULL)&&(p1->data!=p2->data))
p1=p1->link;
if(p1==NULL)
{
p3=(pointer *)malloc(sizeof(struct pointer));
p3->data=p2->data;
p3->link=head3->link;
head3->link=p3;
}
p2=p2->link;
}
}

void jiao(pointer *head1,pointer *head2, pointer *head3){ /*????1???2??*/
pointer *p1,*p2,*p3;
p1=head1->link;
while(p1!=NULL)
{
p2=head2->link;
while((p2!=NULL)&&(p2->data!=p1->data))
{
p2=p2->link;
}
if((p2!=NULL)&&(p2->data=p1->data))
{
p3=(pointer *)malloc(sizeof(struct pointer));
p3->data=p1->data;
p3->link=head3->link;
head3->link=p3;
}
p1=p1->link;
}
}

void cha(pointer *head1,pointer *head2, pointer *head3){ /*????1???2??*/
pointer *p1,*p2,*p3;
p1=head1->link;
while(p1!=NULL)
{
p2=head2->link;
while((p2!=NULL)&&(p2->data!=p1->data))
{
p2=p2->link;
}

if(p2==NULL)
{
p3=(pointer *)malloc(sizeof(struct pointer));
p3->data=p1->data;
p3->link=head3->link;
head3->link=p3;
}
p1=p1->link;
}
}

main(){
pointer *head1,*head2,*head3;
head1=(pointer *)malloc(sizeof(struct pointer));
head1->link=NULL;
head2=(pointer *)malloc(sizeof(struct pointer));
head2->link=NULL;
head3=(pointer *)malloc(sizeof(struct pointer));
head3->link=NULL;
printf("input aggregate 1:\n");
readdata(head1);
printf("input aggregate 2:\n");
readdata(head2);
printf(" aggregate 1 is:\n");
disp(head1);
printf(" aggregate 2 is:\n");
disp(head2);
printf(" aggregate1 bing aggregate2:\n");
bing(head1,head2,head3);
disp(head3);


head3->link=NULL;
printf("aggregate1 jiao aggregate2:\n");
jiao(head1,head2,head3);
disp(head3);
head3->link=NULL;
printf("aggregate1 cha aggregate2:\n");
cha(head1,head2,head3);
disp(head3);
getch();

}

相关文档
相关文档 最新文档