#include using namespace std; template class Node{ public: x data; Node *next; }; template class Queue{ public: Queue (); //~Queue (); void Enqueue (x e); void Dequeue (x& e); int QueueIsFull (); int QueueIsEmpty (); Node* MakeNode (x e); //void QueueRetreive (x& e); private: Node* rear; Node* front; }; int main(){ Queue q; q.Enqueue(2); q.Enqueue(4); q.Enqueue(6); q.Enqueue(8); int e; q.Dequeue(e); cout << e; q.Dequeue(e); cout << e; q.Dequeue(e); cout << e; q.Dequeue(e); cout << e; q.Enqueue(1); q.Enqueue(3); q.Dequeue(e); cout << e; q.Dequeue(e); cout << e; return 0; } template Queue::Queue() { rear = NULL; front = NULL; } template int Queue::QueueIsEmpty() { if (rear == NULL && front == NULL) return 1; return 0; } template int Queue::QueueIsFull() { return 0; } template void Queue::Enqueue(x e) { Node *p = MakeNode(e); if (QueueIsEmpty()){ rear = front = p; } else { p->next = rear; rear = p; } } template void Queue::Dequeue(x &e){ Node *p = new Node; Node *q = new Node; if (rear == front != NULL){ p = front; e = p->data; delete p; front = rear = NULL; } else if (!QueueIsEmpty()){ p = front; q = rear; e = p->data; while(!(q->next == p) && !(front == rear)){ q = q->next; } q->next = NULL; front = q; delete p; } } template Node* Queue::MakeNode(x e) { Node *p = new Node; p->data = e; p->next = NULL; return p; }