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

class below queue with a linked points) The with a tail pointer as the circular

ID: 3832298 • Letter: C

Question

class below queue with a linked points) The with a tail pointer as the circular list-30 linked list is at the head of implements a first-in-first-out queue. It uses a circular singl 2 the in the figure below. this figure, shown In queue and data the tail. 7 at Figure from "Data Abstraction & Problem Solving with Java' by Carrano and public class Myoueue in the diagram private tail null same as last private int aize public int getsize return size: various additional methods private static class Node E. element Node B> next null public Node (E element) this element element Note: If the queue is empty then tail will be null. (a) Implement the enqueue operation for this class. The new element is added at the tail of the queue, becoming the new tail element. Be sure to deal with the special case where the queue is empty when the call is made. public void enqueue (E e)

Explanation / Answer

public void enqueue(E e)
{
   Node current = tail;
   tail = new Node();
tail.next = e;

if(size++ == 0)
       front = last;
  
   else
       current.next = last;
}

public E dequeue()
{
   if (size == 0)
       throw new java.util.NoSuchElementException();
E e = front.data;
   front = front.next;
   if (--total == 0)
       last = null;
return e;
}