#include <iostream>
using namespace std;
template<class T> //定义一个模板
class Stack
{
private:
int SIZE; //栈的大小
int top; //栈顶的位置
T * stac; //T类型的数组
public:
Stack(int size);
~Stack();
int Push(const T & t); //压栈
int Pop(T & t); //出栈
bool isFull();
bool isEmpty();
};
template<class T>
Stack<T>::Stack(int size):SIZE(size),top(-1)
{
stac = new T[SIZE];
}
template<class T>
Stack<T>::~Stack()
{
if(stac!=NULL)
{
delete [] stac;
}
}
template<class T>
int Stack<T>::Push(const T &t)
{
if(isFull()!=0)
{
stac[++top] = t;
return 1;
}
return 0;
}
template<class T>
int Stack<T>::Pop(T &t)
{
if(isEmpty()!=0)
{
t = stac[top--];
return 1;
}
return 0;
}
template<class T>
bool Stack<T>::isEmpty()
{
return top == -1;
}
template<class T>
bool Stack<T>::isFull()
{
return top == SIZE-1;
}
using namespace std;
template<class T> //定义一个模板
class Stack
{
private:
int SIZE; //栈的大小
int top; //栈顶的位置
T * stac; //T类型的数组
public:
Stack(int size);
~Stack();
int Push(const T & t); //压栈
int Pop(T & t); //出栈
bool isFull();
bool isEmpty();
};
template<class T>
Stack<T>::Stack(int size):SIZE(size),top(-1)
{
stac = new T[SIZE];
}
template<class T>
Stack<T>::~Stack()
{
if(stac!=NULL)
{
delete [] stac;
}
}
template<class T>
int Stack<T>::Push(const T &t)
{
if(isFull()!=0)
{
stac[++top] = t;
return 1;
}
return 0;
}
template<class T>
int Stack<T>::Pop(T &t)
{
if(isEmpty()!=0)
{
t = stac[top--];
return 1;
}
return 0;
}
template<class T>
bool Stack<T>::isEmpty()
{
return top == -1;
}
template<class T>
bool Stack<T>::isFull()
{
return top == SIZE-1;
}