/**
stack.hios
*****/ide
#include <iostream>
using namespace std;spa
template <class T>
class Stack
{
public:
Stack(int maxsize = 10);
~Stack(){delete stack;}code
T Top(); void push(const T & x); void pop(); bool empty();
private:
int top;
T * stack;
int maxtop;
};it
template <class T>
Stack::Stack(int maxsize)
{
maxtop = maxsize;
top = -1;
stack = new T[maxsize];
}io
template <class T>
bool Stack::empty()
{
if (top == -1)
{
return true;
}
return false;
}class
template <class T>
T Stack::top()
{
return stack[top];
}stream
template <class T>
void Stack::push (const T & x)
{
top++;
stack[top] = x;
}top
template <class T>
void Stack::pop()
{
top--;
}di
/**
main.cpp
*****/
int main()
{
Stack<int> stack(20); stack.push(1); stack.push(2); return 0;
}