Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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 Result
  intital 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;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote