Solve 5a and 5b Consider a circular queue implemented as a singly-linked list wi
ID: 3933880 • Letter: S
Question
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.Explanation / Answer
#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);
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.