#include<fstream>
#include<iostream>
using namespace std;
ifstream f("l.in");
struct nod{
int info;
nod* urm;
};
nod *prim1, *ultim1, *prim2, *ultim2;
void adaugs(int x, nod *&prim, nod *&ultim)
{
nod*nou=new nod;
nou->info=x;
nou->urm=NULL;
if(prim==NULL) prim=nou;
else ultim->urm=nou;
ultim=nou;
}
void afis(nod *prim)
{ nod *p=prim;
while(p)
{ cout<<p->info<<" ";
p=p->urm;
}
}
int main()
{
int x;
prim1=NULL;
ultim1=NULL;
prim2=NULL;
ultim2=NULL;
while(f>>x)
if(x%2==0) adaugs(x,prim1,ultim1);
else adaugs(x,prim2,ultim2);
afis(prim1);
cout<<endl;
afis(prim2);
cout<<endl;
ultim1->urm=prim2;
afis(prim1);
system("pause");
return 0;
}
|