template
class SeqStack
{
public:
SeqStack ( ) ;
~SeqStack ( ){}
void Push ( T x );//入栈
T Pop ( );//出栈
void Clear();
T GetTop ( );
bool Empty ( );//如果为空则返回真
bool isFull();
void setNull();
private:
T data[MAX_SIZE];//空间大小
int top;//栈顶
int size;
};
#include
#include
template
T SeqStack::Pop () //出栈
{
if(Empty())
{
throw SeqStack::Empty();
}
else
{
return data[top--];
}
}
template
bool SeqStack::Empty ( ) //判断栈是否为空
{
if(top==-1)
return true;
else
return false;
}
template
void SeqStack::Push ( T x) //入栈
{
if(isFull())
{
throw SeqStack::Full();
}
else
{
data[++top]=x;
}
}
template
T SeqStack::GetTop()
{
if(!Empty())
{
return data[top];
}
}
template
SeqStack::SeqStack() //构造空栈(初始化)
{
size=MAX_SIZE;
top=-1;
data=new T[MAX_SIZE];
}
template
SeqStack::~SepStack()//清空栈
{
delete[] data;
}
template
bool SeqStack::isFull()
{
if(top+1==size)
return true;
else
return false;
}
template
void SeqStack::setNull()
{
top=-1;
}
void main() //匹配括号
{
}
1元钱的问答,怎么搞的emm