#include<iostream>
using namespace std;
struct node
{
int data;
node* next;
};
node *build(node* p)
{
int n;
cout<<"请输入链表长度"<<endl;
cin>>n;
p=(node*)malloc(sizeof(node));
node *r,*q;
r=p;
r->next=NULL;
cout<<"请输入"<<n<<"个元素"<<endl;
while(n--)
{
q=(node*)malloc(sizeof(node));
cin>>q->data;
r->next=q;
r=q;
r->next=NULL;
}
return p;
}
void print(node *A)
{
node *y;
y=A->next;
cout<<"该链表的输出结果是"<<endl;
while(y)
{
cout<<y->data<<" ";
y=y->next;
}
cout<<endl;
}
node *function(node *A,node *B,node *C)
{
node *pre,*x,*y,*z,*d,*p,*q;
pre=A;
x=A->next;
y=B->next;
z=C->next;
d=(node*)malloc(sizeof(node));
d->next=NULL;
p=d;
while(y&&z)
{
if(y->data<z->data)
y=y->next;
else if(y->data>z->data)
z=z->next;
else {
q=y->next;
p->next=y;
p=y;
p->next=NULL;
y=q;
z=z->next;
}
}
d=d->next;
while(x&&d)
{
if(x->data<d->data)
{
pre=x;
x=x->next;
}
else if(x->data==d->data)
{
pre=x;
x=x->next;
d=d->next;
}
else {
node* u;
u=d->next;
pre->next=d;
pre=d;
pre->next=x;
d=u;
}
}
if(d)
{
pre->next=d;
}
return A;
}
int main()
{
node *x=0,*y=0,*z=0;
x=build(x);
y=build(y);
z=build(z);
x=function(x,y,z);
print(x);
return 0;
}
链表的集合操作Av(B^C)
最新推荐文章于 2021-05-03 11:32:09 发布