You are on page 1of 2

STIVA

#include <iostream>
#include <cstdlib>
using namespace std;
struct nod
{
int info;
nod* urm;
};
nod* vf;
int optiune,x;
void push(nod*&vf,int x)
{
nod *p;
p=new nod;
p->info=x;
p->urm=vf;
vf=p;
}
void pop(nod*&vf)
{
nod* p=vf;
if(vf==NULL)
cout<<"Stiva vida!!!";
else
{
cout<<"\nNod extras din varful stivei este:";
cout<<vf->info<<" ";
vf=vf->urm;
delete p;
}
}
void afisare(nod*vf)
{
nod *p=vf;
if(vf==NULL)
cout<<"Stiva vida!!!";
else
{
cout<<"\nStiva este: ";
while(p)
{
cout<<p->info<<" ";
p=p->urm;
}
}
}
void menu()
{
system("cls");
cout<<"\n0-exit(Iesire Program)";
cout<<"\n1-Adaugare nod";
cout<<"\n2-Extragere nod";
cout<<"\n3-Afisare Stiva";
cout<<"\nOptiunea dvs: ";
cin>>optiune;
}
int main()
{
menu();
while(optiune!=0)
{
switch(optiune)
{
case 1:
cout<<"\nDati info nod: ";
cin>>x;
push(vf,x);
break;
case 2:
pop(vf);
break;
case 3:
afisare(vf);
break;
}
cout<<"\nContinuati va rog(apasati orice tasta)\n";
system("pause");
menu();
}
return 0;
}

You might also like