已知无头单链表A和B表示两个集合,用算法实现A=A-B补集
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/21 05:38:03
已知无头单链表A和B表示两个集合,用算法实现A=A-B补集
数据结构
数据结构
data_int
#include "head.h"
struct LNode{
// char data[10];
int data;
struct LNode *next;
};
typedef struct LNode * LinkList;
void InitList_L(LinkList &L)//链表构造函数
{
L=new LNode;
L->next=NULL;
}
void PrintList_L(LinkList &H)//链表显示函数
{
LinkList L=H;
L=L->next;
while(1)
{
cout<<"data value is "<<L->data<<endl;
L=L->next;
if (L==NULL)
return;
}
}
void Insert_L(LinkList &H,int n=0)//插入链表
{
LinkList L=H;
LinkList p=L;
int i=0;
if (n==0)
{
n=1;
while(p->next!=NULL)
{
p=p->next;
n++;
}
}
else if (n<1)
{
cout<<"error"<<endl;
return;
}
for (i=0;i<n-1;i++)
{
if (L->next==NULL)
{
cout<<"error"<<endl;
return;
}
L=L->next;
}
p=new LNode;
cout<<"please input a value:";
cin>>p->data;
p->next=L->next;
L->next=p;
}
LinkList bing_LinkList(LinkList a,LinkList b)
{
LinkList c;
LinkList nc;
LinkList t;
InitList_L(c);
nc=c;
a=a->next;
while (a!=NULL)//复制a到c
{
t=new LNode;
t->data=a->data;
nc->next=t;
t->next=NULL;
nc=nc->next;
a=a->next;
}
b=b->next;
while (b!=NULL)
{
nc=c;
while (nc->next!=NULL)
{
if (nc->next->data==b->data)
break;
nc=nc->next;
}
if (nc->next==NULL)
{
t=new LNode;
t->data=b->data;
nc->next=t;
t->next=NULL;
nc=nc->next;
}
b=b->next;
}
return c;
}
void main()
{
LinkList a,b,c;
int i=0;
InitList_L(a);
cout<<"\nI will input date."<<endl;
for (i=1;i<=3;i++)
Insert_L(a,i);
// PrintList_L(a);
InitList_L(b);
cout<<"\nI will input date."<<endl;
for (i=1;i<=3;i++)
Insert_L(b,i);
// PrintList_L(b);
c=bing_LinkList(a,b);
PrintList_L(c);
}
#include "head.h"
struct LNode{
// char data[10];
int data;
struct LNode *next;
};
typedef struct LNode * LinkList;
void InitList_L(LinkList &L)//链表构造函数
{
L=new LNode;
L->next=NULL;
}
void PrintList_L(LinkList &H)//链表显示函数
{
LinkList L=H;
L=L->next;
while(1)
{
cout<<"data value is "<<L->data<<endl;
L=L->next;
if (L==NULL)
return;
}
}
void Insert_L(LinkList &H,int n=0)//插入链表
{
LinkList L=H;
LinkList p=L;
int i=0;
if (n==0)
{
n=1;
while(p->next!=NULL)
{
p=p->next;
n++;
}
}
else if (n<1)
{
cout<<"error"<<endl;
return;
}
for (i=0;i<n-1;i++)
{
if (L->next==NULL)
{
cout<<"error"<<endl;
return;
}
L=L->next;
}
p=new LNode;
cout<<"please input a value:";
cin>>p->data;
p->next=L->next;
L->next=p;
}
LinkList bing_LinkList(LinkList a,LinkList b)
{
LinkList c;
LinkList nc;
LinkList t;
InitList_L(c);
nc=c;
a=a->next;
while (a!=NULL)//复制a到c
{
t=new LNode;
t->data=a->data;
nc->next=t;
t->next=NULL;
nc=nc->next;
a=a->next;
}
b=b->next;
while (b!=NULL)
{
nc=c;
while (nc->next!=NULL)
{
if (nc->next->data==b->data)
break;
nc=nc->next;
}
if (nc->next==NULL)
{
t=new LNode;
t->data=b->data;
nc->next=t;
t->next=NULL;
nc=nc->next;
}
b=b->next;
}
return c;
}
void main()
{
LinkList a,b,c;
int i=0;
InitList_L(a);
cout<<"\nI will input date."<<endl;
for (i=1;i<=3;i++)
Insert_L(a,i);
// PrintList_L(a);
InitList_L(b);
cout<<"\nI will input date."<<endl;
for (i=1;i<=3;i++)
Insert_L(b,i);
// PrintList_L(b);
c=bing_LinkList(a,b);
PrintList_L(c);
}
数据结构算法实现:利用两个线性表LA和LB分别表示两个集合A和B,现要求一个新的集合A=A并B.
假设两个顺序线性表La和Lb分别表示两个集合A和B,如何实现A=A ∩B
已知 集合A中有两个元素a,a平方,集合B中有两个元素1,b,且A=B,求 a和b
A,B是两个集合,请问下符号A'B指的是什么数学意义?A补集和B的交集吗?还有集合C=(A'B')'又是什么
数据结构与算法实习题介绍:A和B的并集:A和B的交集:A和B的差集:实现2个集合的并、交和差的运算.提示:集合的数据元素
一、定义A与B的差集A-B={x|x∈A且x不属于B}.(1)设全集为U,请用集合的交、并、补运算表示A-B与B-A;
C语言编程题,利用两个线性表LA和LB分别表示两个集合A和B,现要求一个集合A=A并B
集合的基本运算,设全集U是由不超过9的正整数组成的集合,集合A,B是其两个子集,且满足A∩B={2},补集A∩补集B={
若U、∅分别表示全集和空集.且A在U中的补集并B=A,则集合A与B必须满足().
已知集合A={x|3小于等于x小于7},B={x|2小于x小于10},求A并B的补集,A交B的补集,A的补集交B,A并B
已知U={1,2,3,4,5}集合A与集合B的并集为U,集合A与集合B的交集不是空集,A与B的补集的交集={1,2}求A
已知全集U=R,集合A=(1,3),B=[a,2a+5].当a=1时,求A交B的补集