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);

}

  1. 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

  1. 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:
  2. Create 10 print jobs.
  3. Add them in an empty priority queue, called printJobHeap.
  4. Display the heap.
  5. 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.
  6. Display the heap.
  7. 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.
  8. Display the heap.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!