#ifndef _QUEUE_H_ #define _QUEUE_H_ template class Node { private: T Data; // The data contained in the node Node *Next; // The pointer to the next node Node *Previous; // The pointer to the previous node public: // Constructor, Destructor // Node( void ); // Default Constructor ~Node( void ); // Default Destructor // Selectors // T GetData( void ) const; // Returns data contained in node Node *GetNext( void ) const; // Returns pointer to next node Node *GetPrev( void ) const; // Returns pointer to previous node // Modifiers // void SetData( T Value ); // Sets the data in the node void SetNext( Node *NextPtr ); // Sets the pointer to the next node void SetPrev( Node *PrevPtr ); // Sets the pointer to the previous node }; template class Queue { private: Node *TAIL; // Points to the last item in the queue Node *HEAD; // Points to the first item in the queue public: // Constructor, Destructor // Queue( void ); // Default constructor ~Queue ( void ); // Default destructor // Selectors // int Size( void ) const; // Returns the number of nodes in the queue bool IsEmpty ( void ) const; // Returns True if the queue is empty // Modifiers // void Enqueue( T Value ); // Adds a new node to the queue T Dequeue( void ); // Removes the next node from the queue }; template Node::Node( void ) { SetPrev(0); SetNext(0); } template Node::~Node( void ) { } template T Node::GetData( void ) const { return (Data); } template Node* Node::GetNext( void ) const { return Next; } template Node* Node::GetPrev( void ) const { return Previous; } template void Node::SetData( T Value ) { Data = Value; } template void Node::SetNext( Node *NextPtr ) { Next = NextPtr; } template void Node::SetPrev( Node *PrevPtr ) { Previous = PrevPtr; } template Queue::Queue( void ) { TAIL = 0; HEAD = 0; } template Queue::~Queue( void ) { while (!IsEmpty()) { Dequeue(); } } template int Queue::Size( void ) const { int Count; if (IsEmpty()) { Count = 0; } else { Node *CountPtr = HEAD; for(Count = 1; CountPtr != TAIL; Count++) { CountPtr = CountPtr->GetNext(); } } return Count; } template bool Queue::IsEmpty( void ) const { return((HEAD == 0) && (TAIL == 0)); } template void Queue::Enqueue( T Value ) { Node *NodePtr = new Node; NodePtr->SetData(Value); NodePtr->SetNext(0); if(IsEmpty()) HEAD = NodePtr; else TAIL->SetNext(NodePtr); TAIL = NodePtr; } template T Queue::Dequeue( void ) { if(IsEmpty()) { } else { T Value = HEAD->GetData(); Node *TempPtr = HEAD; if(HEAD->GetNext() == 0) { HEAD = 0; TAIL = 0; } else HEAD = HEAD->GetNext(); delete TempPtr; return Value; } } #endif /* _QUEUE_H_ */