Se citesc dintr-un fisier text nr care se pun intr-o stiva. Cate cifre sunt in toate nr din stiva? Sa se construiasca o stiva cu nr prime. Sa se stearga elementele din stiva pana la prima aparitie a maximului. Sa se inverseze stiva.
#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;}
int nrcif(int x)
{int i=0;
while(x)
{i++;x=x/10;}
return i;}
int prim(int n)
{int d,i,ok=1;
if(n==1 || n==0)
return 0;
for(d=2;d<=n/2;d++)
if(n%d==0)
ok=0;
return ok;}
int main()
{ifstream f("date");
int x,s=0,m=0,mm=0;
nod* vf=NULL,*vf1=NULL,*p;
while(f>>x)
adaugare(vf,x);
nod* pp=vf;
afisare(vf);
cout<<endl;
vf=pp;
while(vf!=NULL)
{s=s+nrcif(vf->info);
if(prim(vf->info))
adaugare(vf1,vf->info);
if(vf->info>m)
m=vf->info;
vf=vf->urm;}
cout<<s<<" cifre in stiva"<<endl;
afisare(vf1);
cout<<endl;
while(vf1!=NULL)
{ if(vf1->info>mm)
mm=vf1->info;
vf1=vf1->urm;}
int ok=1;
vf=pp;
while(vf!=NULL)
{if(vf->urm->info==m)
{ p=vf;
vf=vf->urm;
delete p;
ok=0;}
if(ok==0)
break;
vf=vf->urm;}
afisare(vf);
cout<<endl;
while(vf1!=NULL)
{if(vf1->info!=mm)
{ p=vf;
vf1=vf1->urm;
delete p;}
vf1=vf1->urm;}
afisare(vf1);
cout<<endl<<endl;
}