Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions 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 }
expand button
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);
}
expand button
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
Check Mark
Knowledge Booster
Background pattern image
Computer Science
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
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education