#include <iostream>
#include "IntStack1.h"

IntStack1::IntStack1(int capacity) : size_(0), capacity_(capacity)
{
  std::cout << "In IntStack1 constructor: capacity = " << capacity_ << "\n"; 
  items_ = new int[capacity_];
}

IntStack1::~IntStack1()
{
  std::cout << "In IntStack1 destructor\n";
  delete[] items_;
}

void IntStack1::Push(int item)
{
  if (size_ == capacity_)
    throw E_PUSH_ON_FULL;

  items_[size_++] = item;
}

int IntStack1::Pop(void)
{
  if (size_ == 0)
    throw E_POP_ON_EMPTY;

  return items_[--size_];
}

bool IntStack1::IsEmpty(void) const
{
  return (size_ == 0);
}

int IntStack1::GetCount(void) const
{
  return size_;
}

std::ostream & operator<<(std::ostream &os, const IntStack1& st)
{
  for (int i = st.size_ - 1; i >= 0; --i)
    std::cout << st.items_[i] << std::endl;
  return os;
}