Question: Can someone help with this exercise? It won't be submitted to anyone. it just to study for a test. Implement the priority queue structure using
Can someone help with this exercise? It won't be submitted to anyone. it just to study for a test.
Implement the priority queue structure using the Heap class.
public class Heap implements PriQueueInterface
{
private Comparable[] elements; // array that holds priority queue elements
private int lastIndex;// index of last element in priority queue
private int maxIndex;// index of last position in array
public Heap(int maxSize)
{
elements = new Comparable[maxSize];
lastIndex = -1;
maxIndex = maxSize - 1;
}
public boolean isEmpty()
// Returns true if this priority queue is empty, false otherwise.
{
return (lastIndex == -1);
}
public boolean isFull()
// Returns true if this priority queue is full, false otherwise.
{
return (lastIndex == maxIndex);
}
- Create the class, PrintJob, to simulate print jobs with the following attributes:
serialNumber: a unique number in order when a print job is created.
numPages: the number of pages of the print job
- Create the main class, HeapDemo, to test the Heap and PrintJob classes where a print job has higher priority if it has fewer pages. The following are the tasks:
- Create 10 print jobs.
- Add them in an empty priority queue, called printJobHeap.
- Display the heap.
- Create 1000 print jobs, then add them into a new empty priority queue, called biggerPrintJobHeap. Use random numbers to determine the number of pages of a print job, with the maximal number of pages 300.
- Display the heap.
- Create 1,000,000 print jobs, then add them into a new empty priority queue, called muchBiggerPrintJobHeap, with the same requirements on the maximal number of pages.
- Display the heap.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
