Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //creati doua stive cu nr din date.in astefel in prima stiva numerele rotunde in a doua in a doua restu si afisati-le continutul
- #include <iostream>
- #include<fstream>
- using namespace std;
- struct stiva
- {
- int info;
- stiva *adr;
- };
- stiva *vfr, *vfo;
- int rotund (int x)
- {
- while(x)
- {
- if(x%2==0)
- return 0;
- x=x/2;
- }
- return 1;
- }
- void push(stiva *&vf, int x)
- {
- if(vf==NULL)
- {
- vf=new stiva;
- vf->adr=NULL;
- vf->info=x;
- }
- else
- {
- stiva *nou;
- nou=new stiva;
- nou->info=x;
- nou->adr=vf;
- vf=nou;
- }
- }
- void creare()
- {
- int x;
- ifstream fin("date.in");
- while(fin>>x)
- if(rotund(x)==1)
- push(vfr,x);
- else
- push(vfo,x);
- }
- void pop(stiva *&vf)
- {
- if(vf==NULL)
- return ;
- stiva *p;
- p=vf;
- cout<<vf->info<<" ";
- vf=vf->adr;
- delete p;
- }
- int main()
- {
- creare();
- while(vfr!=NULL)
- pop(vfr);
- cout<<'\n';
- while(vfo!=NULL)
- pop(vfo);
- cout<<'\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement