#include <iostream>
#include <string>
#define maxsize 100
using namespace std;
template<
class T>
class Stack
{
private:
T arr[maxsize];
int currentSize;
public:
Stack():currentSize(
0) {}
void push(T temp)
{
arr[currentSize++]=temp;
}
T pop()
{
T temp=arr[currentSize-
1];
arr[currentSize-
1]=NULL;
currentSize--;
return temp;
}
bool empty()
{
return (currentSize==
0)?
true:
false;
}
bool full()
{
return (currentSize==
100)?
true:
false;
}
int size()
{
return currentSize;
}
int top()
{
return currentSize;
}
};
int main()
{
string type=
"";
int length,tempInt,n;
double tempDouble;
char tempChar;
while(
cin>>type&&type!=
"STOP")
{
cin>>length;
if(type==
"Int")
{
Stack<
int> Int;
for(
int i=
0; i<length; i++)
{
cin>>tempInt;
if(Int.full())
cout<<
"full!! ";
else Int.push(tempInt);
}
cin>>n;
for(
int i=
0; i<n; i++)
{
if(!Int.empty())
cout<<Int.pop();
else cout<<
"empty!!";
cout<<((i!=n-
1)?
" ":
"\n");
}
}
else if(type==
"Double")
{
Stack<
double> Double;
for(
int i=
0; i<length; i++)
{
cin>>tempDouble;
if(Double.full())
cout<<
"full!! ";
Double.push(tempDouble);
}
cin>>n;
for(
int i=
0; i<n; i++)
{
if(!Double.empty())
cout<<Double.pop();
else cout<<
"empty!!";
cout<<((i!=n-
1)?
" ":
"\n");
}
}
else if(type==
"Char")
{
Stack<
char> Char;
for(
int i=
0; i<length; i++)
{
cin>>tempChar;
if(Char.full())
cout<<
"full!! ";
Char.push(tempChar);
}
cin>>n;
for(
int i=
0; i<n; i++)
{
if(!Char.empty())
cout<<Char.pop();
else cout<<
"empty!!";
cout<<((i!=n-
1)?
" ":
"\n");
}
}
}
return 0;
}
Sample input
Int
10 1 2 3 4 5 6 7 8 9 10
5
Double
5 0.8 4.5 6.2 5.4 12.9
7
Char
8 g h s a f o i p
6
STOP
Sample output
10 9 8 7 6
12.9 5.4 6.2 4.5 0.8 empty!! empty!!
p i o f a s