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