/* This class specifies the basic operation on a queue as a linked list */ #ifndef DATA_STRUCTURES_QUEUE_H_ #define DATA_STRUCTURES_QUEUE_H_ #include #include /** Definition of the node */ template struct node { Kind data; node *next; }; /** Definition of the queue class */ template class queue { public: /** Show queue */ void display() { node *current = queueFront; std::cout << "Front --> "; while (current != NULL) { std::cout << current->data << " "; current = current->next; } std::cout << std::endl; std::cout << "Size of queue: " << size << std::endl; } /** Default constructor*/ queue() { queueFront = NULL; queueRear = NULL; size = 0; } /** Destructor */ ~queue() {} /** Determine whether the queue is empty */ bool isEmptyQueue() { return (queueFront == NULL); } /** Add new item to the queue */ void enQueue(Kind item) { node *newNode; newNode = new node; newNode->data = item; newNode->next = NULL; if (queueFront == NULL) { queueFront = newNode; queueRear = newNode; } else { queueRear->next = newNode; queueRear = queueRear->next; } size++; } /** Return the first element of the queue */ Kind front() { assert(queueFront != NULL); return queueFront->data; } /** Remove the top element of the queue */ void deQueue() { node *temp; if (!isEmptyQueue()) { temp = queueFront; queueFront = queueFront->next; delete temp; size--; } else { std::cout << "Queue is empty !" << std::endl; } } /** Clear queue */ void clear() { queueFront = NULL; } private: node *queueFront; /**< Pointer to the front of the queue */ node *queueRear; /**< Pointer to the rear of the queue */ int size; }; #endif // DATA_STRUCTURES_QUEUE_H_