#include<stdio.h> |
#include<malloc.h> |
#include<stdlib.h> |
#include<iostream> |
using namespace std; |
typedef int ElemType; //假设线性表中的元素均为整型 |
typedef struct |
{ |
ElemType* elem; //存储空间基地址 |
int length; //表中元素的个数 |
} SqList; //顺序表类型定义 |
int ListCreate_Sq(SqList &L, int n) |
{ |
L.elem= new ElemType[n]; |
for ( int i=0; i<n; i++) |
cin>>L.elem[i]; |
L.length=n; |
return 1; |
} |
void ListPrintf_Sq(SqList &L) |
{ |
ElemType *p; |
cout<<L.length; |
for (p=L.elem; p<L.elem+L.length; ++p) |
printf ( " %d" ,*p); |
cout<<endl; |
} |
void Listjiao(SqList &a,SqList &b,SqList &c) |
{ |
c.elem= new ElemType[200]; |
int p,i,j; |
for (i=0;i<a.length;i++) |
c.elem[i]=a.elem[i]; |
c.length=a.length; |
for (i=0,j=a.length;i<b.length;i++) |
{ |
for (p=0;p<a.length;p++) |
{ |
if (a.elem[p]==b.elem[i]) |
break ; |
} |
if (p==a.length) |
{ |
c.elem[j++]=b.elem[i]; |
c.length++; |
} |
} |
} |
void Listbing(SqList &a,SqList &b,SqList &c) |
{ |
c.elem= new ElemType[100]; |
c.length=0; |
int i,j,p; |
for (i=0;i<a.length;i++) |
{ |
for (j=0;j<b.length;j++) |
{ |
if (b.elem[j]==a.elem[i]) |
c.elem[c.length++]=a.elem[i]; |
} |
} |
} |
void Listcha(SqList &a,SqList &b,SqList &c) |
{ |
c.elem= new ElemType[100]; |
c.length=0; |
int i,j; |
for (i=0; i<a.length; i++) |
{ |
for (j=0; j<b.length; j++) |
{ |
if (b.elem[j]==a.elem[i]) |
break ; |
} |
if (j==b.length) |
c.elem[c.length++]=a.elem[i]; |
} |
} |
int main() |
{ |
SqList La,Lb,L1,L2,L3; |
int a,b; |
cin>>a>>b; |
ListCreate_Sq(La,a); |
ListCreate_Sq(Lb,b); |
Listjiao(La,Lb,L1); |
Listbing(La,Lb,L2); |
Listcha(La,Lb,L3); |
ListPrintf_Sq(L1); |
ListPrintf_Sq(L2); |
ListPrintf_Sq(L3); |
return 0; |
} |