Doua variabile dinamice memoreaza DOB a doua persoane. Sa se afiseze persoana mai tanara.
#include<iostream>Se citesc nr de la tastatura pana la 0. Sa se creeze o stiva cu nr. Sa se afiseze stiva. Sa se afiseze suma el. Sa se afisee nr de el ale stivei. Sa se afiseze primele doua el din stiva. Sa se stearga stiva.
using namespace std;
struct DOB{
int a,l,z;
};
int main()
{DOB *p,*q;
p=new DOB;
q=new DOB;
cin>>(*p).a>>p->l>>p->z;
cin>>q->a>>q->l>>q->z;
if(p->a>q->a)
cout<<"a doua persoana";
else if(p->a<q->a)
cout<<"a doua persoana";
else if(p->l>q->l)
cout<<"a doua persoana";
else if(p->l<q->l)
cout<<"a doua persoana";
else if(p->z>q->z)
cout<<"a doua persoana";
else if(p->z<q->z)
cout<<"a doua persoana";
else cout<<"=";
delete p,q;
}
#include<iostream>
using namespace std;
struct nod{
int info;
nod *urm;};
void adaug(int x, nod* &vf)
{nod* p;
p=new nod;
p->info=x;
p->urm=vf;
vf=p;}
void afisare(nod* vf)
{while(vf!=NULL){
cout<<vf->info<<" ";
vf=vf->urm;}
}
int main()
{nod *vf=NULL,*p;
int x,s=0,i=0;
cin>>x;
while(x)
{adaug(x,vf);
cin>>x;}
afisare(vf);
p=vf;
while(vf!=NULL){
s+=vf->info;
vf=vf->urm;}
cout<<endl<<"Suma "<<s<<endl;
vf=p;
while(vf!=NULL){
i++;
vf=vf->urm;}
cout<<i<<" elemente in stiva"<<endl;
vf=p;
cout<<"Primele doua elemente din stiva ";
while(vf!=NULL){
i--;
if(i==1 || i==0)
cout<<vf->info<<" ";
vf=vf->urm;}
vf=p;
while(vf!=NULL)
{p=vf;
delete p;
vf=vf->urm;}
}