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

The linked implementation of a queue has two data fields. The field firstNode re

ID: 3578371 • Letter: T

Question

The linked implementation of a queue has two data fields. The field firstNode references the queue's front element; lastNode references the element at the back of the queue. Consider the following method where the object item is of the generic type T; isEmpty () is a method that returns true if the queue is empty; setNextNode (newNode) is a setter method of the private class Node of the linked implementation of a queue, which sets a value to the data field next of the node. public void xxxxxx(T item){Node newNode = new Node(item, null); if (isEmpty()) firstNode = newNode; else lastNode.setNextNode(newNode); lastNode - newNode;} What does the method xxxxxx do? Suggest a self-explaining name for the method.

Explanation / Answer

The given function, adds new node to the queue...

firstNode points to firstnode of the queue..

lastNode points to lastnode of the queue..

if queue is empty it adds newnode to queue, firstNode and lastNode are updated and same..

if queue is not empty, new node is added last and lastNode is updated to newNode..

Name for the method should be Enqueue(T item)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote