怎样用C语言实现集合的并交呢?

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/29 20:25:53

怎样用C语言实现集合的并交呢?
怎样用C语言实现集合的并交呢?

怎样用C语言实现集合的并交呢?
#include
#include
typedef struct pointer{
\x05char dat;
\x05struct pointer *link;
} pointer;
void readdata(pointer *head)
{ //读集合
\x05pointer *p;
\x05char tmp;
\x05printf("input data ('0' for end):");
\x05scanf("%c",&tmp);
\x05while(tmp!='0')
\x05{
\x05\x05if((tmp'z'))
\x05\x05{
\x05\x05\x05printf("输入错误!必须为小写字母!\n");
\x05\x05\x05return;
\x05\x05}
\x05\x05p=(pointer *)malloc(sizeof(struct pointer));
\x05\x05p->dat=tmp;
\x05\x05p->link=head->link;
\x05\x05head->link=p;
\x05\x05scanf("%c",&tmp);
\x05}
}
void disp(pointer *head)
{ //显示集合数据
\x05pointer *p;
\x05p=head->link;
\x05while(p!=NULL)
\x05{
\x05\x05printf("%c ",p->dat);
\x05\x05p=p->link;
\x05}
\x05printf("\n");
}
void bing(pointer *head1,pointer *head2,pointer *head3)
{ //计算集合1与集合2的并
\x05pointer *p1,*p2,*p3;
\x05p1=head1->link;
\x05while(p1!=NULL)
\x05{
\x05\x05p3=(pointer *)malloc(sizeof(struct pointer));
\x05\x05p3->dat=p1->dat;
\x05\x05p3->link=head3->link;
\x05\x05head3->link=p3;
\x05\x05p1=p1->link;
\x05}
\x05p2=head2->link;
\x05while(p2!=NULL)
\x05{
\x05\x05p1=head1->link;
\x05\x05while((p1!=NULL)&&(p1->dat!=p2->dat))
\x05\x05\x05p1=p1->link;
\x05\x05if(p1==NULL)
\x05\x05{
\x05\x05\x05p3=(pointer *)malloc(sizeof(struct pointer));
\x05\x05\x05p3->dat=p2->dat;
\x05\x05\x05p3->link=head3->link;
\x05\x05\x05head3->link=p3;
\x05\x05}
\x05\x05p2=p2->link;
\x05}
}
void jiao(pointer *head1,pointer *head2,pointer *head3)
{ //计算集合1与集合2的交
\x05pointer *p1,*p2,*p3;
\x05p1=head1->link;
\x05while(p1!=NULL)
\x05{
\x05\x05p2=head2->link;
\x05\x05while((p2!=NULL)&&(p2->dat!=p1->dat))
\x05\x05\x05p2=p2->link;
\x05\x05if((p2!=NULL)&&(p2->dat=p1->dat))
\x05\x05{
\x05\x05\x05p3=(pointer *)malloc(sizeof(struct pointer));
\x05\x05\x05p3->dat=p1->dat;
\x05\x05\x05p3->link=head3->link;
\x05\x05\x05head3->link=p3;
\x05\x05}
\x05\x05p1=p1->link;
\x05}
}
main()
{
\x05pointer *head1,*head2,*head3;
\x05head1=(pointer *)malloc(sizeof(struct pointer));
\x05head1->link=NULL;
\x05head2=(pointer *)malloc(sizeof(struct pointer));
\x05head2->link=NULL;
\x05head3=(pointer *)malloc(sizeof(struct pointer));
\x05head3->link=NULL;
\x05printf("输入集合1:\n");
\x05readdata(head1);
\x05getchar();
\x05printf("输入集合2:\n");
\x05readdata(head2);
\x05printf("集合1为:\n");
\x05disp(head1);
\x05printf("集合2为:\n");
\x05disp(head2);
\x05printf("集合1与集合2的并为:\n");
\x05bing(head1,head2,head3);
\x05disp(head3);
\x05head3->link=NULL;
\x05printf("集合1与集合2的交为:\n");
\x05jiao(head1,head2,head3);
\x05disp(head3);
}

怎样用C语言实现集合的并交呢? 本人碰见一道C语言难题,利用C语言实现:求任意两个集合的交集、并集、差集, 怎样用C语言实现1!+2!+3! 本人碰见一道C语言难题,寻大神帮助,利用C语言实现:求任意两个集合的交集、并集、差集,兄弟感激不尽 编写程序,实现两个集合的交运算(用C语言)1、已知两个整数集合中的数据以递增次序分别存放在数组A,B中,编写程序实现两个集合的交运算(即取两个集合相同的数据元素),并把得到的交 数据结构 用c语言写的 集合的并、交和差运算的程序基本要求:(1)集合的元素限定为小写字母字符〔‘a’..'z'〕.(2)演示程序以用户和计算机的对话方式执行.实现提示:以有序链表表示 用链表实现集合的交集并集差集最好用C语言来编,高手用的是C++吧,不过一样很感激! 什么是辗转相除法怎样用c语言编程实现,用辗转相除法求两个数的最大公约数 c++定义一个集合类,怎样用操作符重载实现交集并集运算 请问在单片机中,怎样用左移(右移)与简单逻辑运算实现循环左移(右移)c语言实现的 已知递增有序的单链表 A,B和C分别存储了一个集合设计算法实现 A:=A∪(B∩C),并使求解结构A仍保持递增.要求算法的时间复杂度为 O(|A|+|B|+|C|).其中,|A|为集合A 的元素个数.用C语言实现. 怎样用C语言做求两个数的商 C语言能输入连续的数字并计算吗?例如和实现∑函数的功能,怎么实现? 设计一个关于复数的结构类型,并实现复数的四则运算C语言 数据结构(C语言)用单链表存储一元多项式,并实现两个多项式的相加运算 编写一个程序用单链表存储多项式,并实现两个多项式相加的函数?C/C++语言 VC++编写 实现2个集合的并、交和差的运算介绍:A和B的并集:A和B的交集:A和B的差集:实现2个集合的并、交和差的运算.提示:集合的数据元素为整数,A、B集合最多允许25个数据元素.程序允 集合的交集和并集运算 求C语言大神