Write C++ a function that dequeues a node and returns the node that was dequeued
ID: 3595451 • Letter: W
Question
Write C++ a function that dequeues a node and returns the node that was dequeued.
The function is a member of a class called Queue. Write the function definition only for deQueue. Other methods have been defined and you do not need to write them. Given below is the class definition:
For example:
Test Resultintital q = 3 4 5 6 node* temp = q.deQueue(); cout<< "deleted val=="<<temp->value<<endl; q.display();
deleted val==3 4 5 6
intial q = 3 node* temp = q.deQueue(); cout<< "deleted val=="<<temp->value<<endl; q.display();
deleted val==3 queue is empty
Explanation / Answer
{
struct node *temp;
if(front==NULL && rear==NULL)
return NULL; // Here we are checking if queue is empty
else
{
temp=front; //We are initialzing front to temp;
front=front->next; //Move front by one position
}
return temp;
}
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.