Oto kod:
Kod: Zaznacz cały
#include <cstdlib>
#include <iostream>
#include <stack>
using namespace std;
struct Element
{
int dane;
Element *nast;
};
void push(Element **S)
{
Element *temp=new Element;
cin >> temp->dane;
temp->nast=*S;
*S=temp;
}
void top(Element **S)
{
if (*S)
{
Element *temp=*S;
*S=(*S)->nast;
cout << temp->dane << endl;
delete temp;
}
}
int pop(Element *S)
{
Element *temp;
if (S!=NULL)
{
return S-> dane;
}
}
int empty(Element *S)
{
if( S == 0 )
cin >> "Stos jest pusty";
else
cin >> "Stos nie jest pusty";
return 0;
}
int main()
{
Element *S=NULL, *temp = NULL;
char warunek;
while (cin >> warunek)
{
switch (warunek)
{
case 'd':
push(&S);
break;
case 't':
top(&S);
break;
case 'u':
pop(S);
break;
case 'e':
empty(S);
break;
}
}
system("PAUSE");
return 0;
}