Solve 5a and 5b Consider a circular queue implemented as a s
Solve 5a and 5b
Consider a circular queue implemented as a singly-linked list with one pointer to the back. Remember to consider any special cases. class Q_node {public: int data; Q_node *next;}; class Queue {public: Queue(); Queue(const Queue & Org); ~Queue(); void enQueue(int key)\\\\ void deQueue(); private: Q_node *back;}; Implement the default constructor for the Queue class. Implement the enQueue for the Queue class. Implement the deQueue for the Queue class. Implement the copy constructor for the Queue class.Solution
#include<iostream>
class Q_node
{
public:
int data;
Q_node *next;
};
class Queue
{
public:
Queue();
void enQueue(int key);
private:
Q_node *back;
};
Queue::Queue()
{
back = NULL;
}
void Queue::enQueue(int key)
{
Q_node *newNode = new Q_node;
newNode->data = key;
if(back == NULL)
{
back = newNode;
back->next = newNode;
}
else
{
newNode->next = back->next;
back->next = newNode;
back = newNode;
}
}
int main()
{
Queue q;
q.enQueue(5);
q.enQueue(10);
}
