18. Give the line numbers of the code presented in Figure 3.26 that perform the
ID: 670979 • Letter: 1
Question
18. Give the line numbers of the code presented in Figure 3.26 that perform the garbage collection for the structure Queue.
Here is editable Figure 3.26
public clas Queue
{private Listing [] data;
private int size;
private int numOfNodes;
private int front;
private int rear;
public Queue ()
{
size = 100;
numOfNodes = 0;
front = 0;
rear = 0;
data = new Listing [n];
}
public boolean enque(Listing newNode)
{
if(numOfNodes == size)
return false; //** overflow error **
else
{
numOfNodes = numOfNodes + 1;
data[rear] = newNode.deepCopy();
rear = (rear + 1) % size;
return true; //push operation succesful**
}
}
public Listing deque()
{
int frontLocation;
if(numOfNodes == 0)
return null; //**underflow error**
else
{
frontLocation = front;
front = (front + 1) % size;
numOfNodes = numOfNodes - 1;
return data[frontLocation];
}
}
public void showAll()
{
int i = front;
for(int c = 1; c <= numOfNodes; c++)
{
System.out.println(data[i].toString());
i = (i + 1) % size;
}
} // end of showAll method
} //end of class Queue
Explanation / Answer
No garbage collection is being performed in this code. Please give the full code, including the Listing class and main method!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.