//头文件SeqStack.h
#ifndef SeqStack_H
#define SeqStack_H
const int StackSize=10;
template<class DataType>
class SeqStack
{
public:
SeqStack();
~SeqStack(){}
void Push (DataType x);
DataType Pop();
DataType GetPop();
int Empty();
private:
DataType data[StackSize];
int top;
};
#endif
//源文件SeqStack.cpp
#include "SeqStack.h"
template<class DataType>
SeqStack<DataType>::SeqStack()
{
top = -1;
}
template<class DataType>
void SeqStack<DataType>::Push(DataType x)
{
if(top==StackSize-1)throw"上溢";
top++;
data[top]=x;
}
template<class DataType>
DataType SeqStack<DataType>::Pop()
{
DataType x;
if(top== -1)throw"下溢";
x = data[top--];
return x;
}
template<class DataType>
DataType SeqStack<DataType>::GetPop()
{
if(top!= -1)
return data[top];
}
template<class DataType>
int SeqStack<DataType>::Empty()
{
if(top== -1) return 1;
else return 0;
}
//主函数SeqStack_main.cpp
#include "SeqStack.h"
template<class DataType>
SeqStack<DataType>::SeqStack()
{
top = -1;
}
template<class DataType>
void SeqStack<DataType>::Push(DataType x)
{
if(top==StackSize-1)throw"上溢";
top++;
data[top]=x;
}
template<class DataType>
DataType SeqStack<DataType>::Pop()
{
DataType x;
if(top== -1)throw"下溢";
x = data[top--];
return x;
}
template<class DataType>
DataType SeqStack<DataType>::GetPop()
{
if(top!= -1)
return data[top];
}
template<class DataType>
int SeqStack<DataType>::Empty()
{
if(top== -1) return 1;
else return 0;
}
<img src="https://img-blog.csdn.net/20141109151256726?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvSmlhX0Jpbg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />