Se citesc numere dintr-un fisier text. Scrieti o functie care verifica daca elementul din varful stivei mai apare in stiva. Afisati numarul de elemente pare din stiva. Stergeti elemente din stiva pana la intalnirea unui nr de 3 cifre (care nu se sterge).
#include<iostream>Sa se inverseze o stiva. // NON-FINISHATA
#include<fstream>
using namespace std;
struct nod{
int info;
nod* urm;};
void afisare(nod* vf)
{if(vf==NULL)
cout<<"Stiva goala";
else
while(vf!=NULL)
{cout<<vf->info<<" ";
vf=vf->urm;}
}
void adaugare(nod* &vf, int x)
{nod* p;
p=new nod;
p->info=x;
p->urm=vf;
vf=p;}
void verif_vf(nod* vf)
{int x=vf->info,ok=0;
while(vf->urm!=NULL)
{if(vf->urm->info==x)
ok=1;
vf=vf->urm;}
if(ok==1)
cout<<x<<" (varful) mai apare in stiva";
else cout<<x<<" (varful) nu mai apare in stiva";
}
int nrpare(nod* vf)
{int i=0;
while(vf!=NULL)
{if(vf->info%2==0)
i++;
vf=vf->urm;
}
return i;
}
void stergere(nod* &vf)
{nod* p;
while(vf->info>999 || vf->info<100)
{p=vf;
vf=vf->urm;
delete p;}
}
int main()
{nod* vf=NULL;
ifstream f("date");
int x;
while(f>>x)
adaugare(vf,x);
afisare(vf);
cout<<endl;
verif_vf(vf);
cout<<endl;
cout<<nrpare(vf)<<" nr pare"<<endl;
stergere(vf);
afisare(vf);
}
#include<iostream>
#include<fstream>
using namespace std;
struct nod{
int info;
nod* urm;};
void afisare(nod* vf)
{if(vf==NULL)
cout<<"Stiva goala";
else
while(vf!=NULL)
{cout<<vf->info<<" ";
vf=vf->urm;}
}
void adaugare(nod* &vf, int x)
{nod* p;
p=new nod;
p->info=x;
p->urm=vf;
vf=p;}
void verif_vf(nod* vf)
{int x=vf->info,ok=0;
while(vf->urm!=NULL)
{if(vf->urm->info==x)
ok=1;
vf=vf->urm;}
if(ok==1)
cout<<x<<" (varful) mai apare in stiva";
else cout<<x<<" (varful) nu mai apare in stiva";
}
int nrpare(nod* vf)
{int i=0;
while(vf!=NULL)
{if(vf->info%2==0)
i++;
vf=vf->urm;
}
return i;
}
void STADT_C(nod* &vf)
{nod* p;
while(vf->info>999 || vf->info<100)
{p=vf;
vf=vf->urm;
delete p;}
}
int main()
{nod* vf=NULL;
ifstream f("date");
int x;
while(f>>x)
adaugare(vf,x);
afisare(vf);
cout<<endl;
int nr=0,i=1,j;
while(vf!=NULL)
{nr++;
vf=vf->urm;}
nod* p=vf;
while(i<nr/2 && vf!=NULL)
{j=1;
p=vf;
while(j<nr-i)
{p=p->urm;
j++;}
vf->urm=p->urm;
vf->info=p->info;
i++;
}
afisare(p);
}