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)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.