#include <iostream>

using namespace std;

template <class T>
class Stack {
public:
  Stack();
  ~Stack();
  bool empty();
  void push(T thing);
  T pop();

private:
  T *data;
  int capacity;
  int size;  
};

template <class T>
Stack<T>::Stack() {
  capacity = 1000;
  data = new T[capacity];
  size = 0;
}

template <class T>
Stack<T>::~Stack() {
  delete [] data;
}

template <class T>
bool Stack<T>::empty() {
  return (size == 0);
}

template <class T>
void Stack<T>::push(T thing) {
  // check if we need to grow the data array
  if (size == capacity) {
    T *old = data;
    capacity *= 2;      
    data = new T[capacity];
    // copy old data into new array
    for (int i = 0; i < capacity; i++)
      data[i] = old[i];
  }
  
  data[size] = thing;
  size++;
}  

template <class T>
T Stack<T>::pop() {
  size--;
  return data[size];
}  

int main() {
  Stack<char> test;

  test.push('o');
  test.push('l');
  test.push('l');
  test.push('e');
  test.push('h');

  while (!test.empty()) {
    cout << test.pop();
  }

  cout << '\n';

  return 0;
}

