const int StackSize = 10;
template<typename DataType>
class SeqStack{
public:
SeqStack();
~SeqStack();
void Push(DataType x);
DataType Pop();
DataType GetTop();
int Empty();
private:
DataType data[StackSize];
int top;
};
入栈
template<typename DataType>
void SeqStack<DataType>::Push(DataType x){
if(top==StackSize-1) throw"上溢";
data[++top]=x;
}
出栈
template<typename DataType>
DataType SeqStack<DataType>::Pop(){
DataType x;
if(top==-1) throw"下溢";
x=data[top--];
return x;
}