Question: Listing 24.8, uses a heap to implement the priority queue. Revise the implementation using a sorted array list to store the elements and name the
Listing 24.8, uses a heap to implement the priority queue. Revise the implementation using a sorted array list to store the elements and name the new class PriorityQueueUsingSortedArrayList. The elements in the array list are sorted in increasing order of their priority with the last element having the highest priority. Write a test program that generates 5 million integers and enqueues them to the priority and dequeues from the queue. Use the same numbers for MyPriorityQueue and PriorityQueueUsingSortedArraList and display their execution times.
Data from Listing 24.8,


1 publ1c class MyPriorityQueue { private Heap heap: heap for priority queue publ1c void MyPriorityQueue heap.add (new Heap (): no-arg constructor public MyPriorityQueue (java.util.Comparator c) { heap = new Heap (c): constructor 9 10 11 12 public void enqueue (E newObject) { enqueue -234 5679 a012
Step by Step Solution
3.27 Rating (156 Votes )
There are 3 Steps involved in it
import javautilComparator public class Exercise2406 public static void mainStri... View full answer
Get step-by-step solutions from verified subject matter experts
