早教吧作业答案频道 -->其他-->
已知无头单链表A和B表示两个集合,用算法实现A=A-B补集数据结构
题目详情
已知无头单链表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 "<data< 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"< return;
}
for (i=0;i {
if (L->next==NULL)
{
cout<<"error"< 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."< for (i=1;i<=3;i++)
Insert_L(a,i);
// PrintList_L(a);
InitList_L(b);
cout<<"\nI will input date."< 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 "<
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"<
}
for (i=0;i
if (L->next==NULL)
{
cout<<"error"<
}
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."<
Insert_L(a,i);
// PrintList_L(a);
InitList_L(b);
cout<<"\nI will input date."<
Insert_L(b,i);
// PrintList_L(b);
c=bing_LinkList(a,b);
PrintList_L(c);
}
看了 已知无头单链表A和B表示两个...的网友还看了以下:
如图所示,a是电压表的负接线柱引出的导线头,开关S闭合后,a接b时,电压表的示数是6V,a接d时, 2020-05-23 …
( )也被称为“具有风险管理目标的综合数据” A.中间计量数据B.组合结果数据C.信息储存 2020-05-30 …
请同学们利用数轴探究|a-2|+|a+1|的最小值,提示:结合数轴a的范围进行分类讨论 2020-06-05 …
如图所示,a是电压表的负接线柱引出的导线头,开关S闭合后,a接b时,电压表的示数是6V,a接d时, 2020-07-11 …
求证a^4+4是一个合数(a是整数,且绝对值a不等于1) 2020-07-25 …
下列说法中正确的个数是()①合数的因数至少有3个②能被1和它本身整除的数,叫素数③奇数一定是素数, 2020-07-31 …
若a是最小的自然数,b是最小的质数,c是最小的合数,则a+b+c=? 2020-11-06 …
如图所示,a是电压表的负接线柱引出的导线头,开关S闭合后,a接b时,电压表的示数是5V,a接d时,电 2020-12-05 …
某派对中有10位宾客.志辉和诗慧是其中2位宾客.他们各与2位宾客握手.已知志辉和诗慧没有握手.(1) 2021-01-08 …
如果●表示一个质数,■表示一个合数,那么下列()的结果一定是合数.A.●+■B.●×■C.●-■ 2021-02-05 …