您现在的位置是:主页 > news > 网站备案公告/东莞seo优化推广

网站备案公告/东莞seo优化推广

admin2025/5/12 22:42:49news

简介网站备案公告,东莞seo优化推广,品牌网站建设公司哪好,网站开发,自定义首页显示线性表)已知递增有序的单链表A,B分别存储了一个集合,请编程以求出两个集合A和B 的差集(即由在A中出现且在B中不出现的元素所构成的集合),并以同样的形式存储,同时返回该集合的元素个数。#includeusing namespace std;#define NULL 0int i,len…

网站备案公告,东莞seo优化推广,品牌网站建设公司哪好,网站开发,自定义首页显示线性表)已知递增有序的单链表A,B分别存储了一个集合,请编程以求出两个集合A和B 的差集(即由在A中出现且在B中不出现的元素所构成的集合),并以同样的形式存储,同时返回该集合的元素个数。#includeusing namespace std;#define NULL 0int i,len…

线性表)已知递增有序的单链表A,B分别存储了一个集合,请编程以求出两个集合A和B 的差集(即由在A中出现且在B中不出现的元素所构成的集合),并以同样的形式存储,同时返回该集合的元素个数。

#include

using namespace std;

#define NULL 0

int i,len,j,n,m;

struct linklist     //定义结构体

{

int num;

linklist *next;

};

linklist *creat()    //尾插法建立链表

{   int x;

cin>>m;

linklist *p1,*head,*p2;//p1用于指向新建立的结点,p2指向尾结点

p1=new linklist;

for(x=1;x<=m;x++)

{

cin>>p1->num;

if(x==1) head=p1;

p2=p1;

p1=new linklist;

p2->next=p1;

if(x==m) p2->next=NULL;

}

return head;

}

void build_print_linklist(linklist *a,linklist *b)  //两条链表取差集的函数

{

linklist *p1,*p2,*head,*p,*c,*p3;

p1=a;p2=b;

int m=0,n=0;

while(p1!=NULL)        //遍历p1

{

n=0;p2=b;

while(p2!=NULL)     //移动p2,寻找在p1中出现却不在p2中出现的值

{

if(p2->num==p1->num) n=1;  //有相等的值,记录n=1

p2=p2->next;

}

if(n==0)

{

/******************/

添加代码

/******************/

if(m==1) c=p,p3=p;    //差集存放才c中

else

{

p3->next=p;

p3=p;

}

}

p1=p1->next;

}

p3->next=NULL;

n=0;

while(c!=NULL)         //输出差集

{

n++;

cout<num<

c=c->next;

}

cout<

cout<

}

void destroy(struct linklist *head)

{

struct linklist *p;

while(head!=NULL)

{

p=head->next;

delete(head);

head=p;

}

}

int main()

{

linklist *heada,*headb;//建立两条链表,由build_print_linklist函数执行A-B并输出

heada=creat();

headb=creat();

build_print_linklist(heada,headb);

destroy(heada);

destroy(headb);

return 0;

}