////  Lab #10 - 2203 Section 2
////                               

#include <iostream>
#include <cstddef>

using namespace std;

template <class ItemType>
StackType<ItemType>::StackType()
{
  top = NULL;
}

template <class ItemType>
void StackType<ItemType>::push(ItemType x)
{
  NodeType<ItemType> *p = new NodeType<ItemType>;
  if(p == NULL)
    cout << "Error:  Out of memory space" << endl;
  else
  {  
    p->info = x;
    p->next = top;
    top = p;
  }
}

template <class ItemType>
ItemType StackType<ItemType>::pop()
{
  if(IsEmpty() == true)
      cout << "Stack is empty" << endl;
  else 
  {
    NodeType<ItemType> *p = new NodeType<ItemType>;
    p = top;
    top = p->next;
    ItemType a = p->info;
    delete p;
    return a;
  }
}

template <class ItemType>
bool StackType<ItemType>::IsEmpty()
{
  if(top == NULL)
    return true;
  else
    return false;
}

