#include<iostream>
using namespace std;
template <class T>
class SeqStack
{
public:
SeqStack()
{
top = -1;
}
~SeqStack() {}
void Push(T x);
T pop();
T GetTop();
int Empty();
private:
T data[100];
int top;
};
template<class T>
void SeqStack<T>::Push(T x)
{
if (top == 99)
throw"over flow";
top++;
data[top] = x;
}
template<class T>
T SeqStack<T>::pop()
{
if (top == -1)
throw"under flow";
T x = data[top--];
return x;
}
template<class T>
T SeqStack<T>::GetTop()
{
if (top == -1)
throw"under flow";
T x = data[top-1];
return x;
}
template<class T>
int SeqStack<T>::Empty()
{
if (top == -1)
return 1;
return 0;
}
int main()
{
return 0;
}
栈的简单代码
最新推荐文章于 2024-04-05 16:38:09 发布