#include <string>
#include <iostream>
using namespace std;
template <class T>
class Mystack{
public:
Mystack(int max);
int size(void);
bool push(T t);
bool pop(T& t);
bool printall(void);
bool isempty(void){
if(i <= 0)
return true;
else
return false;
}
bool isfull(void){
if(i >= max)
return true;
else
return false;
}
private:
int max, i;
T t[0xff];
protected:
};
template <class T>
Mystack<T>::Mystack(int max){
if(max > 0xfe)
this->max = 0xfe;
else
this->max = max;
i = 0;
}
template <class T>
int Mystack<T>::size(void){
return i;
}
template <class T>
bool Mystack<T>::push(T t){
if(isfull()){
cout << "The Stack is full!" << endl;
return false;
} else{
this->t[++i] = t;
return true;
}
}
template <class T>
bool Mystack<T>::pop(T& t){
if(isempty()){
cout << "The Stack is empty!" << endl;
return false;
} else{
t = this->t[i--];
return true;
}
}
template <class T>
bool Mystack<T>::printall(void){
if(isempty())
return false;
else {
for(int i = 1; i <= size(); i++){
cout << t[i] << " ";
}
cout << endl;
return true;
}
}
int main(void){
Mystack<int> s(18);
int x;
s.push(8);
s.push(3);
s.push(5);
s.printall();
s.push(12);
s.push(33);
s.printall();
s.pop(x);
s.printall();
for(int i = 0; i < 20; i++) {
s.push(i + 6);
}
s.printall();
for(int i = 0; i < 20; i++) {
s.pop(x);
}
s.printall();
}