Docstoc
EXCLUSIVE OFFER FOR DOCSTOC USERS
Try the all-new QuickBooks Online for FREE.  No credit card required.

data structures

Document Sample
data structures Powered By Docstoc
					using namespace std;

template<class T>
class stack
{
private:
      T *arr;
      int maxsize;
      int top;
      void full();
      void empty();
public:
      stack();
      stack(int size);
      bool isfull();
      bool isempty();
      void push(T val);
      T pop();
      T gettop();
};
template<class T>
stack<T>::stack()
{
      maxsize=10;
      top=-1;
      arr=NULL;
}
template<class T>
stack<T>::stack(int size)
{
      maxsize=size;
      top=-1;
      arr=new T[maxsize];
}
template<class T>
void stack<T>::full()
{
      cout<<" THE STACK IS FULL CURRENTLY SO.....YOU CAN'T ADD
MORE"<<endl;
}
template<class T>
void stack<T>::empty()
{
      cout<<" THE STACK IS EMPTY CURRENTLY SO.....YOU CAN'T POP/GET
MORE"<<endl;
}
template<class T>
bool stack<T>::isempty()
{
      return(top==-1);
}
template<class T>
bool stack<T>::isfull()
{
      return(top==maxsize-1);
}
template<class T>
void stack<T>::push(T val)
{
      if(!isfull())
      {
            arr[++top]=val;
      }
      else
      {
            full();
      }
}
template<class T>
T stack<T>::pop()
{
      T val;
      if(!isempty())
      {
            //val=arr[top];
            val=arr[top];
            top--;
            return val;
      }
      else
      {
            empty();
            return 0;
      }
}

template <class T>
T stack<T>::gettop()
{
      return arr[top];
}

				
DOCUMENT INFO
Shared By:
Stats:
views:2
posted:2/23/2012
language:
pages:2