Está en la página 1de 2

#ifndef _STACK_TEMPLATE

#define _STACK_TEMPLATE
template <class BaseType>class Stack{
public:
Stack();
~Stack();
bool is_empty() const;
bool is_full() const;
bool push (const BaseType &value);
bool pop (BaseType &value);
bool pop ();
BaseType top() const;
private:
static const int MAX_SIZE = 10000;
int top_index;
BaseType stack[MAX_SIZE];
};

template <class BaseType>


bool Stack<BaseType>::is_empty() const
{
return (top_index == -1);
}
template <class BaseType>
bool Stack<BaseType>::is_full() const
{
return (top_index == MAX_SIZE-1);
}

template <class BaseType>


bool Stack<BaseType>::push (const
BaseType &value)
{
bool result = false;
if (top_index < MAX_SIZE - 1)
{
top_index++;
stack[top_index]=value;
result = true;
}
return result;
}

template <class BaseType>


bool Stack<BaseType>::pop ()
{
bool result = false;
if (top_index != -1)
{
top_index--;
result = true;
}
return result;
}

template <class BaseType>


bool Stack<BaseType>::pop (BaseType &value)
{
bool result = false;
if (top_index != -1)
{
value = stack[top_index];
top_index--;
result = true;
}
return result;
}

template <class BaseType>


BaseType Stack<BaseType>::top() const
{
return stack[top_index];
}#endif

También podría gustarte