```
#ifndef QUEUE_H
#define QUEUE_H
enum Error_code {success,overflow,underflow};
template <typename Queue_entry>
class Queue {
public:
Queue();
bool empty()const;
Error_code append(const Queue_entry &);
Error_code serve();
Error_code retrieve(Queue_entry &)const;
~Queue();
Queue(const Queue &);
Queue &operator=(const Queue &);
protected:
struct Node {
Queue_entry data;
Node *next;
};
Node *front,*rear;
};
template<typename Queue_entry>
Queue<Queue_entry>::Queue() {
rear = front = NULL;
}
template<typename Queue_entry>
Queue<Queue_entry>::Queue(const Queue &x) {
rear = front = NULL;
Node *orginalFront = x.front,*orignalRear = x.rear,*q,*p = NULL;
if (orginalFront != NULL) {
front = new Node;
p = NULL;
front->data = orginalFront->data;
front->next = NULL;
p = front;
while (orginalFront != NULL) {
q= new Node;
q->data = orginalFront->data;
q->next = NULL;
p->next = q;
orginalFront = orginalFront->next;
}
rear = q;
}
}
template<typename Queue_entry>
Error_code Queue<Queue_entry>::append(const Queue_entry &x) {
Node *p = new Node;
p->data = x;
p->next = NULL;
if (rear != NULL ) rear->next = p;
rear = p;
if (front == NULL) front = rear;
return success;
}
template<typename Queue_entry>
Error_code Queue<Queue_entry>::retrieve(Queue_entry &item) const{
if (!empty() ) {
item = front->data;
return success;
}
return underflow;
}
template<typename Queue_entry>
Error_code Queue<Queue_entry>::serve() {
if (!empty() ) {
Node *q = front;
front = front->next;
if (front == NULL) rear = NULL;
delete q;
return success;
}
return underflow;
}
template<typename Queue_entry>
bool Queue<Queue_entry>::empty() const {
if (front == NULL) return true;
return false;
}
template<typename Queue_entry>
Queue<Queue_entry> &Queue<Queue_entry>::operator =(const Queue<Queue_entry> &x)
{
if (this != &x) {
Node *p = front;
while (front != NULL) {
p = front;
front = front->next;
delete p;
}
rear = front = NULL;
Node *orginalFront = x.front,*orignalRear = x.rear,*q;
if (orginalFront != NULL) {
front = new Node;
p = NULL;
front->data = orginalFront->data;
front->next = NULL;
p = front;
while (orginalFront != NULL) {
q= new Node;
q->data = orginalFront->data;
q->next = NULL;
p->next = q;
orginalFront = orginalFront->next;
}
rear = q;
}
}
return *this;
}
template<typename Queue_entry>
Queue<Queue_entry>::~Queue()
{
Node *p = front;
while (front != NULL) {
p = front;
front = front->next;
delete p;
}
}
#endif
```