Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cu nr din fisierul date.in creati 2 liste, prima in care adaugati nr. pare si a doua cu nr. impare. afisati pe cate o linie continutul lor
- #include <fstream>
- #include <iostream>
- using namespace std;
- ifstream f("date.in");
- ofstream g("date.out");
- struct nod{
- int info;
- nod *adr;
- };
- nod *prim;
- nod *prim1;
- void creare()
- {
- nod *p,*nou,*p1,*nou1;
- int y;
- while(f>>y)
- {
- if(prim==NULL||prim1==NULL)
- {
- if(prim==NULL&&y%2==0)
- {
- prim= new nod;
- prim->info=y;
- p=prim;
- }
- if(prim1==NULL&&y%2==1)
- {
- prim1= new nod;
- prim1->info=y;
- p1=prim1;
- }
- }
- else
- {
- if(y%2==0)
- {nou=new nod;
- nou->info=y;
- p->adr=nou;
- p=nou;
- }
- if(y%2==1)
- {
- nou1=new nod;
- nou1->info=y;
- p1->adr=nou1;
- p1=nou1;
- }
- }
- }
- p->adr=NULL;
- p1->adr=NULL;
- }
- void parcurgere()
- {
- nod *p=prim;
- nod *p1=prim1;
- while(p)
- {
- cout<<p->info<<" ";
- p=p->adr;
- }
- cout<<'\n';
- while(p1)
- {
- cout<<p1->info<<" ";
- p1=p1->adr;
- }
- }
- int main()
- {
- creare();
- parcurgere();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement