subject
Computers and Technology, 26.10.2021 20:50 kratose

Write a method for the Queue class in the queue. java program (Listing 4.4) that displays the contents of the queue. Note that this does not mean simply displaying the contents of the underlying array. You should show the queue contents from the first item inserted to the last, without indicating to the viewer whether the sequence is broken by wrapping around the end of the array. Be careful that one item and no items display properly, no matter where front and rear are. Listing 4.4 is below
class Queue
{
private int maxSize;
private long[] queArray;
private int front;
private int rear;
private int nItems;
//
public Queue(int s)
{
maxSize = s;
queArray = new long[maxSize];
front =0;
rear = -1;
nItems = 0;
}
//
public void insert(long j)
{
if(rear == maxSize -1)
rear = -1;
queArray[++rear] = j;
nItems++;
}
//
public long remove()
{
long temp = queArray[front++];
if(front == maxSize)
front = 0;
nItems--;
return temp;
}
//
public long peekFront()
{
return queArray[front];
}
//
public boolean isEmpty()
{
return(nItems==0);
}
//
public boolean isFull()
{
return (nItems==maxSize);
}
//
public int size()
{
return nItems;
}
//
} //end class
class QueueApp
{
public static void main(String[] args)
{
Queue theQueue = new Queue(5);
theQueue. insert(10);
theQueue. insert(20);
theQueue. insert(30);
theQueue. insert(40);
theQueue. remove();
theQueue. remove();
theQueue. remove();
theQueue. insert(50);
theQueue. insert(60);
theQueue. insert(70);
theQueue. insert(80);
while( !theQueue. isEmpty() )
{
long n = theQueue. remove();
System. out. print(n);
System. out. print( " ");
}
System. out. println(" ");
} //end main()
} //end class

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 08:00
What best describes a career pathway in a lodging career? a worker starts out as an amusement attendant, then becomes a recreation worker, and then becomes a gaming worker within five years. a worker starts out as a bell hop, then becomes a night clerk, and then becomes a hotel manager within five years. a worker starting out as a tour guide, then becomes a travel clerk, and then becomes a travel agent within five years. a worker starts out as a server, then becomes a food preparer, and then becomes a head chef within five years.
Answers: 1
question
Computers and Technology, 22.06.2019 09:00
Which best describes the condition under which the unicode output is the same as plain text?
Answers: 3
question
Computers and Technology, 22.06.2019 20:00
What side length would you specify if you were required to create a regular hexagonal plate that was composed of 33 cm(squared) of sheet metal? dimension the side length to 0.1 cm
Answers: 2
question
Computers and Technology, 23.06.2019 10:00
Whats three fourths of 15(this is supposed to be in math but i clicked too fast)
Answers: 1
You know the right answer?
Write a method for the Queue class in the queue. java program (Listing 4.4) that displays the conten...
Questions
question
Mathematics, 21.01.2021 20:20
question
English, 21.01.2021 20:20
question
Chemistry, 21.01.2021 20:20
question
Mathematics, 21.01.2021 20:20
Questions on the website: 13722367