// Name: Stack.h // Author: J. Michael Word // Date Written: 8/1/97 // Purpose: implement a object stack from a list // Reference: based on (with extensive changes), // An Introduction to Object-Oriented Programming in C++ // Graham Seed, Springer-Verlag, 1996. #ifndef STACK_H #define STACK_H 1 #include "List.h" #include "ListIter.h" template class Stack : protected List { public: Stack() : List() {} Stack(const Stack& s) : List(s) {} bool empty() const { return List::empty(); } int size() const { return List::size(); } void push(T obj) { insertBefore(obj, List::START); } T pop() { T obj = List::operator*(); drop(List::START); return obj; } const T& top() const { return List::operator*(); } friend ostream& operator << (ostream& s, const Stack& l); }; template inline ostream& operator << (ostream& s, const Stack& l) { return s << ((List&)l); } #endif