Java Programming Lab Test
Java Programming Lab Test
Laboratory Exercise 6
Queues
Objectives:
At the end of the exercise, the students should be able to:
Identify how queues are used as data structure
Debug the given program to obtain the required outputs
Materials:
Procedures:
Activity1
Given the program below, debug and modify the application to acquire the following outputs:
o 36.0 98.0 546.0 687.0 957.0
o 546.0 687.0 36.0 98.0 957.0
class PriorityQ {
private int maxSize;
private double[] queArray;
private int nItems;
//-----------------------------------------------------------public Priority(int s) {
maxSize = s;
queArray = new double[maxsize];
nItems = 0;
}
//----------------------------------------------------------public void insert(double item) {
int j;
if(nItems==0)
queArray[nItems++] = item;
else {
for(j=nItems-1; j>=0; j--) {
if(item > queArray[j])
queArray[i+1] = item;
else
break;
}
queArray[j+1] = item;
nItems--;
}
}
//----------------------------------------------------------public double remove() {
return queArray[--nItems];
}
//----------------------------------------------------------public double peekMin() {
return queArray[nItems-1];
}
//----------------------------------------------------------public boolean isEmpty() {
return(nItems==0);
}
Laboratory Exercise 6
*Property of STI
Page 1 of 3
G0016
*Property of STI
Page 2 of 3
G0016
Laboratory Exercise 6
*Property of STI
Page 3 of 3