-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkedqueue.h
More file actions
executable file
·107 lines (83 loc) · 2.95 KB
/
Copy pathlinkedqueue.h
File metadata and controls
executable file
·107 lines (83 loc) · 2.95 KB
1
/***************************************************************************** ** File: linkedqueue.h ** ** Author: Robb T. Koether ** ** Date: Mar 8, 1999 ** ** Abstract: This file contains the definition of the LinkedQueue ** template class ** ** Note: You should use either the LinkedList with Tail or a ** DoublyLinkedList as the base class. Otherwise, the ** queue member functions will be very slow. ** *****************************************************************************/#ifndef LINKED_QUEUE_H#define LINKED_QUEUE_H// Include files#include <iostream>#include <string>#include <cassert>#include "circlinkedlist.h"using namespace std;/***************************************************************************** ** The LinkedQueue template class definition ** *****************************************************************************/template<class T>class LinkedQueue : private CircLinkedList<T>{// Public member functions public: // Constructors LinkedQueue() {} LinkedQueue(const LinkedQueue<T>& queue) : CircLinkedList<T>(queue) {} // Inspectors T Head() const {return CircLinkedList<T>::GetElement(1);} int Size() const {return CircLinkedList<T>::Size();} bool Empty() const {return CircLinkedList<T>::Empty();} // Mutators void Enqueue(const T& value) {PushBack(value);} T Dequeue() {T value = CircLinkedList<T>::GetElement(1); CircLinkedList<T>::PopFront(); return value;} void MakeEmpty() {CircLinkedList<T>::MakeEmpty();} // Facilitators void Input(istream& in) {CircLinkedList<T>::Input(in);} void Output(ostream& out) const {CircLinkedList<T>::Output(out);} // Other member functions void Validate() const {CircLinkedList<T>::Validate();}};// Operatorstemplate <class T>istream& operator>>(istream& in, LinkedQueue<T>& queue);template <class T>ostream& operator<<(ostream& out, const LinkedQueue<T>& queue);/***************************************************************************** ** Function: operator>> ** ** Purpose: To extract a queue from the input stream ** *****************************************************************************/template <class T>istream& operator>>(istream& in, LinkedQueue<T>& queue){ queue.Input(in); return in;}/***************************************************************************** ** Function: operator<< ** ** Purpose: To insert a queue into the output stream ** *****************************************************************************/template <class T>ostream& operator<<(ostream& out, const LinkedQueue<T>& queue){ queue.Output(out); return out;}#endif