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 18:30
Which of the following commands is more recommended while creating a bot?
Answers: 1
question
Computers and Technology, 23.06.2019 06:00
What machine listens for http requests to come in to a website’s domain? a. a router b. a browser c. a server d. a uniform resource locator
Answers: 1
question
Computers and Technology, 23.06.2019 11:30
Me dangers of social media and the internetexplain what each means: 1) social media and phones have become an addiction.2) outside people have access to you all the time.3) cyberstalking4) cyberbullying5) catphishing6) viruses7) identity theft8) credit card fraud9) hacking10) money schemes
Answers: 1
question
Computers and Technology, 25.06.2019 09:50
In any one-minute interval, the number of requests for a popular web page is a poisson random variable with expected value 240 requests. (a) a web server has a capacity of requests per minute. if the number of requests in a one-minute interval is greater than the server is overloaded. use the central limit theorem to estimate the smallest value of for which the probability of overload is less than 0.035. note that your answer must be an integer. also, since this is a discrete random variable, don't forget to use "continuity correction". = 268 (b) now assume that the server's capacity in any one-second interval is ⌊/60⌋, where ⌊⌋ is the largest integer ≤ (this is called the floor function.) for the value of derived in part (a), what is the probability of overload in a one-second interval? this time, don't approximate via the clt, but compute the probability exactly.
Answers: 2
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, 18.10.2020 09:01
question
Mathematics, 18.10.2020 09:01
question
History, 18.10.2020 09:01
question
Mathematics, 18.10.2020 09:01
question
Physics, 18.10.2020 09:01
Questions on the website: 13722360