//  StackType.cpp in  StackType3/


template<class ItemType>
StackType<ItemType>::StackType()   //default ctor.  stack size of 500 items
{
    maxStack = 500;
    top = -1;
    items = new ItemType[500];
};

template<class ItemType>
StackType<ItemType>::StackType(int size)  //ctor of 1 int argument.
{
    maxStack = size;
    top = -1;
    items = new ItemType[size];
}

template<class ItemType>
StackType<ItemType>::~StackType()
{
  delete [] items;  //dlete the dynamically allocated memory
  cout << "hi from dtor  " << maxStack << endl;   //demo.  to see that they're
  //called.
}

template<class ItemType>
void StackType<ItemType>::MakeEmpty()
{
    top = -1;
}

template<class ItemType>
bool StackType<ItemType>::IsEmpty() const
{
    return (top == -1);
}

template<class ItemType>
bool StackType<ItemType>::IsFull() const   //slight difference from StackType2
{
    return (top == maxStack - 1);
}

template<class ItemType>         //change from textbook.  Checks for overflow
void StackType<ItemType>::Push(ItemType newItem)
{
  if (!IsFull()) {
      top++;
      items[top] = newItem;
  }
  else
    cout << "ERROR.  Stack is full.  Item not added" << endl;
}

template<class ItemType>
void StackType<ItemType>::Pop(ItemType& item)
{
    item = items[top];
    top--;
}
