// Implement a generic stack class using templates.


#include <iostream.h>
#include <string.h>


template<class T>
class stack {

    public:

    stack(size_t size = 10);
    ~stack();
    friend ostream &operator<<(ostream &os, const stack &s);

    private:

    T *base;
    T *top;
    size_t size;

};


template<class T>
stack<T>::stack(size_t size) {
    base = new T[size];
    top = this->base - 1;
    size = size;
}


template<class T>
stack<T>::~stack() {
    delete[] base;
}


template<class T>
ostream &operator<<(ostream &os, const stack<T> &s) {
    for (T *ptr = s.top ; ptr >= s.base ; ptr--) {
        os << *ptr << endl;
    }
    return os;
}
