#include<fstream.h>
fstream f("nr.in",ios::in);
struct nod{int info;
nod *leg;
};
nod *prim,*pare,*impare;
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(prim,x);
}
void separ(nod *prim,nod *&pare,nod *&impare)
{nod *p=prim;
while(p){if(p->info%2==0)adaugf(pare,p->info);
else adaugf(impare,p->info);
p=p->leg;
}
}
void afis(nod *prim)
{nod *p=prim;
while(p){cout<<p->info<<" ";
p=p->leg;
}
cout<<endl;
}
void main()
{citire();
separ(prim,pare,impare);
afis(pare);
afis(impare);
}
|