#ifndef Stack_h #define Stack_h const int null = 0; template class Stack { private: struct Node { DataType data; Node* previous; public: explicit Node(const DataType& data, Node* previous = null) : data(data), previous(previous) { } }; private: Node* last; public: Stack() : last(null) { } ~Stack() { clear(); } inline bool empty() const { return last == null; } void clear() { for (Node* current = last; last; current = last, last = last->previous ) delete current; } bool push(const DataType& data) { return ( last = new Node(data, last) ); } DataType pop() { DataType result = last->data; Node* temp = last; last = last->previous; delete temp; return result; } private: Stack(const Stack& other); const Stack& operator=(const Stack& other); }; #endif