早教吧作业答案频道 -->其他-->
已知无头单链表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实验室制较纯净乙 2020-04-08 …
项目实验现象和结论A.比较催化效果左试管比右试管放出气泡快--MnO2比CuO的催化效果好B.比较 2020-05-02 …
英语选择和结论A.isB.are1.Thereapenandthreebooksonthetabl 2020-05-13 …
发现身边的历史——我写我家写广东省东莞市高埗镇有关的,分A文和B文.A文:探究活动成果.真实的记录 2020-05-17 …
一种生物不同组织细胞的蛋白质和DNA分子,其组成和结构A.蛋白质相同,DNA不同 B.DNA相同,蛋 2020-05-25 …
HIN1病毒,肺鼠疫杆菌和蘑菇都有的物质和结构A细胞壁B细胞膜C细胞核D核酸我知道是D, 2020-06-03 …
下列实验“操作和现象”与“结论”对应关系正确的是()操作和现象结论A常温下,将铝箔插入浓硝酸中,无 2020-07-01 …
数据结构算法实现:利用两个线性表LA和LB分别表示两个集合A和B,现要求一个新的集合A=A并B.利 2020-07-27 …
请问两个互不相同的条件同时满足后其结果的概率问题.如果满足条件1得出结果为出现A的概率是60%,B是 2020-11-15 …
现有两杯无色液体,只知道其中一杯是水,一杯是食盐水,请用不同的方法区别他们,简述实验方案,现象和结论 2020-12-23 …