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

Which if any of the following code segments correctly implements the Add() metho

ID: 3817769 • Letter: W

Question

Which if any of the following code segments correctly implements the Add() method? Void Queue:: Add (int n) {if (IsFull ()) throw QueueFull (): else {Node^+ temp = new Node; temp - > data = n; temp - > next = NULL; if (rear == NULL) front = temp; else rear - > next = temp;}} void Queue:: Add (int n) {if (IsFull ()) throw QueueFull (): else {Node^+ temp = new Node; temp - > data = n; temp - > next = NULL; if (front == NULL) front = temp; else rear = temp;}} void Queue:: Add (int n) {Node^+ temp = new Node; temp - > data = NULL; temp - > next = n; if (rear == NULL; else rear - >next = temp; rear = temp;}} None of the answers provided void Queue:: Add (int n) {if (IsFull ()) throw QueueFull (); else {Node^* temp = new Node; temp - > data = n; temp - > next = rear; If (front == NULL) front = temp; else temp = rear - > next; rear = temp;}} Which if any of the following code segments correctly implements the Queue destructor? Queue:: approx

Explanation / Answer

22.

B

Node *temp = new node; //create new node

temp->data = n;   // set data of new node = n

temp->next = NULL;

if(front == NULL) //queue is empty

front = temp; // add element in front

else

rear = temp; // add element at rear

In A and C, if (rear == NULL) is wrong deletion occurs from front , so front is checked for empty queue not rear.

In D , temp->next = rear is wrong as we need to add the element at rear in the queue.

23.

C.

Queue::~Queue()

{

int temp;

While( !IsEmpty())

temp = Remove(); //call Remove() which remove elements of queue from front

}

A and B is wrong as it delete only front and rear pointers. The in between elements are not removed. B has wrong class specifier.

D is wrong as it assume front as an array.

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