/****************************
* date:2015-07-20
* Description:stack.h
*****************************/
#ifndef _stack_h
#define _stack_h
Template<class t>
Class stack{
Public
Stack (int maxstacksize = 10);
~stack () {delete [] Stack;}
BOOL IsEmpty () const {return top = =-1;}
BOOL Isfull () const {return top = = Maxtop;}
T Top () const;
stack<t>& Push (const t& val);
T Pop ();
Private
int top;
int maxtop;
T *stack;
};
//
Template<class t>
Stack<t>::stack (int maxstacksize/* = 10 */)
{
top =-1;
Maxtop = MaxStackSize-1;
stack = new T[maxstacksize];
}
//
Template<class t>
stack<t>& stack<t>::P ush (const t& val)
{
if (Isfull ())
{
Cerr << "Stack space is full" << Endl;
Exit (Exit_failure);
}
Stack[++top] = val;
return *this;
}
//
Template<class t>
T stack<t>::top () const
{
if (IsEmpty ())
{
Cerr << "Stack space is empty" << Endl;
Exit (Exit_failure);
}
return stack[top];
}
//
Template<class t>
T Stack<t>::P op ()
{
if (IsEmpty ())
{
Cerr << "Stack space is empty" << Endl;
Exit (Exit_failure);
}
return stack[top--];
}
#endif//_stack_h
Stack of data structures (array implementations)