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 14:20
Cengagenowv2 is a comprehensive online learning tool. using cengagenowv2, you may access all of the following except: 2. each time you log in, cengagenowv2 automatically performs a system check and informs you if your computer does not meet the cengagenowv2 system requirements. 3. which tab/page allows you to easily track your assignment scores, number of submissions, time spent, as well as the ability view assign
Answers: 3
question
Computers and Technology, 24.06.2019 02:30
Assume a class window with accessor method getwidth that accepts no parameters and returns an integer. assume further an array of 3 window elements named winarr, has been declared and initialized. write a sequence of statements that prints out the width of the widest window in the array.
Answers: 2
question
Computers and Technology, 24.06.2019 14:30
In a home that has 120 v service, there is an electric appliance that has a resistance of 12 ohms. how much power will this appliance consume? a. 10 w b. 120 w c 1200 w d. 1440 w
Answers: 1
question
Computers and Technology, 24.06.2019 16:30
The database design steps are listed below in the incorrect order. choose the correct order number next to each step. determine the information to be stored in the database. determine the fields needed to record the data determine if there will be any repetition of data entered, and separate the fields into tables to normalize the data. create relationships to connect the tables.
Answers: 3
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
Social Studies, 29.04.2021 14:00
question
Mathematics, 29.04.2021 14:00
question
History, 29.04.2021 14:00
Questions on the website: 13722365