#include<fstream>
#include<iostream>
using namespace std;
struct nod{
char culoare;
nod* urm;};
void adaugare_coada(nod* &prim,nod* &ultim,char x)
{nod* p=new nod;
p->culoare=x;
p->urm=NULL;
if(prim==NULL)
prim=p;
else ultim->urm=p;
ultim=p;}
void adaugare_stiva(nod* &vf, int x)
{nod* p;
p=new nod;
p->culoare=x;
p->urm=vf;
vf=p;}
void afisare(nod* vf)
{if(vf==NULL)
cout<<"Stiva/Coada goala";
else
while(vf!=NULL)
{cout<<vf->culoare<<" | ";
vf=vf->urm;}
cout<<endl;
}
int main()
{nod *c1=NULL,*c2=NULL,*c=NULL,*uc1=NULL,*uc2=NULL;
ifstream f("date");
char x;
int n;
f>>n;
int i=0;
while(i<n/2)
{f>>x;
i++;
adaugare_coada(c1,uc1,x);
}
while(f>>x)
adaugare_coada(c2,uc2,x);
afisare(c1);
afisare(c2);
while(c1 && c2)
{adaugare_stiva(c,c1->culoare);
c1=c1->urm;
if(c->culoare=='R')
while(c)
{adaugare_coada(c2,uc2,c->culoare);
c=c->urm;}
if(c1 && c2)
{adaugare_stiva(c,c2->culoare);
c2=c2->urm;
if(c->culoare=='R')
while(c)
{adaugare_coada(c1,uc1,c->culoare);
c=c->urm;}
}
}
}
Orar semigroup #2
5/30 - Joc carti
marți, 29 mai 2012
by DlMuresan
Categories:
carti,
coada,
joc,
stiva
|
Leave a comment