can you explain why the code shown below does not output: pineapple lime and how to fix it when using the driver program shown in screen shot to test. i also attach of the LLNode class // Note: It is important to implement this file as a circular queue without 'front' pointer public class CircularLinkedQueue implements QueueInterface { protected LLNode rear; // reference to the rear of this queue protected int numElements = 0; public CircularLinkedQueue() { rear = null; } public void enqueue(T element) { // Adds element to the rear of this queue. LLNode newNode = new LLNode(element); if (isEmpty()) { rear = newNode; newNode.setLink(newNode); numElements++; } else { rear = newNode; newNode.setLink(rear.getLink()); rear.setLink(newNode); numElements++; } } public T dequeue() { // Throws QueueUnderflowException if this queue is empty; // otherwise, removes front element from this queue and returns it if (isEmpty()) throw new QueueUnderflowException("Dequeue attempted on empty queue"); else { T element; rear = rear.getLink(); element = rear.getInfo(); rear.setInfo(null); if (rear.getLink() == null) rear = null; numElements--; return element; } } public String toString() { String result = "\n"; LLNode cursor = rear; while (cursor != null){ result+=(cursor.getInfo()); cursor = cursor.getLink();   } return result; } public boolean isEmpty() { // Returns true if this queue is empty; otherwise, returns false. return (numElements == 0); } public boolean isFull() { // Returns false - a linked queue is never full. return false; } public int size() { // Returns the number of elements in this queue. return numElements; } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

can you explain why the code shown below does not

output:

pineapple

lime

and how to fix it when using the driver program shown in screen shot to test.

i also attach of the LLNode class

// Note: It is important to implement this file as a circular queue without 'front' pointer

public class CircularLinkedQueue<T> implements QueueInterface<T> {

protected LLNode<T> rear; // reference to the rear of this queue

protected int numElements = 0;

public CircularLinkedQueue() {

rear = null;

}

public void enqueue(T element) {

// Adds element to the rear of this queue.

LLNode<T> newNode = new LLNode<T>(element);

if (isEmpty()) {

rear = newNode;

newNode.setLink(newNode);

numElements++;

}

else {

rear = newNode;

newNode.setLink(rear.getLink());

rear.setLink(newNode);

numElements++;

}

}

public T dequeue() {

// Throws QueueUnderflowException if this queue is empty;

// otherwise, removes front element from this queue and returns it

if (isEmpty())

throw new QueueUnderflowException("Dequeue attempted on empty queue");

else {

T element;

rear = rear.getLink();

element = rear.getInfo();

rear.setInfo(null);

if (rear.getLink() == null)

rear = null;

numElements--;

return element;

}

}

public String toString() {

String result = "\n";

LLNode<T> cursor = rear;

while (cursor != null){

result+=(cursor.getInfo());

cursor = cursor.getLink();

 

}

return result;

}

public boolean isEmpty() {

// Returns true if this queue is empty; otherwise, returns false.

return (numElements == 0);

}

public boolean isFull() {

// Returns false - a linked queue is never full.

return false;

}

public int size() {

// Returns the number of elements in this queue.

return numElements;

}

}

public class LLNode<T> {
protected LLNode<T> link;
protected T info;
5
7
public LLNode (T info) {
this.info = info;
link = null;
}
80
9
10
11
12
public void setInfo(T info) {
this.info = info;
}
130
14
15
16
public T getInfo() {
return info;
}
170
18
19
20
210
22
public void setLink(LLNode<T> link) {
this.link = link;
}
23
24
250
public LLNode<T> getLink() {
return link;
}
26
27
28 }
Transcribed Image Text:public class LLNode<T> { protected LLNode<T> link; protected T info; 5 7 public LLNode (T info) { this.info = info; link = null; } 80 9 10 11 12 public void setInfo(T info) { this.info = info; } 130 14 15 16 public T getInfo() { return info; } 170 18 19 20 210 22 public void setLink(LLNode<T> link) { this.link = link; } 23 24 250 public LLNode<T> getLink() { return link; } 26 27 28 }
public class Driver {
public static void main(String[] args) {
CircularLinkedQueue<String> cq = new CircularLinkedQueue<String>();
mit
try {
System.out.println(cq.dequeue());
} catch (Exception e) {
menm
ww vm
wwwww
}
cq.enqueue("Tomato");
cg.enqueue("Grape");
cg.dequeue();
cg.dequeue();
cg.engueue("Pineapple");
cg.enqueue("Lime");
System.out.printIn(ca);
}
Transcribed Image Text:public class Driver { public static void main(String[] args) { CircularLinkedQueue<String> cq = new CircularLinkedQueue<String>(); mit try { System.out.println(cq.dequeue()); } catch (Exception e) { menm ww vm wwwww } cq.enqueue("Tomato"); cg.enqueue("Grape"); cg.dequeue(); cg.dequeue(); cg.engueue("Pineapple"); cg.enqueue("Lime"); System.out.printIn(ca); }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Generic Type
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education