#include<fstream.h>
fstream f("f1.in",ios::in);
fstream g("f2.in",ios::in);
struct nod{int info;
nod*leg;
};
nod *p1,*p2, *p3, *p4;
void adaugf(nod *&prim,int x)
{nod *nou=new nod;
nou->info=x;
nou->leg=prim;
prim=nou;
}
void citire()
{int x;
while(f>>x)adaugf(p1,x);
while(g>>x)adaugf(p2,x);
}
void afis(nod *prim)
{nod *p=prim;
while(p){cout<<p->info<<" ";p=p->leg;}
cout<<endl;
}
int gasit(nod *prim,int x)
{nod *p=prim;
while(p){if(p->info==x)return 1;
p=p->leg;
}
return 0;
}
void reuniune(nod *p1,nod *p2, nod *&p3)
{nod *p=p1;
while(p){
adaugf(p3,p->info);
p=p->leg;
}
p=p2;
while(p)
{if(!gasit(p1,p->info))adaugf(p3,p->info);
p=p->leg;
}
}
void intersectie(nod *p1,nod *p2, nod *&p3)
{nod *p=p2;
while(p)
{if(gasit(p1,p->info))adaugf(p3,p->info);
p=p->leg;
}
}
void main()
{citire();
reuniune(p1,p2,p3);
afis(p3);
intersectie(p1,p2,p4);
afis(p4);
}
|