Jvyxmv
Jvyxmv
Sem. 1, 2011/2012
MAXPRIORITY+1 queues. To insert an object of priority p into the priority queue, pass the item and its priority p as arguments and add it to the back of the queue priority[p]. So, each queue contains only elements of equal priority in the order of their insertion. When removing an element from the priority queue, find the nonempty queue of largest index and pop the queue. Use this design strategy to implement the class QPQueue. 2. You can use program 15.3 to check whether your priority queue works or not.. the initial class design is given below. Please complete the other implementation of isEmpty(), push(), pop(), peek() and size(). interface Queue<T> boolean isEmpty() Returns true if the queue is empty and false otherwise. T peek() Returns the element at the front of the queue with the highest priority. T pop() Erases an element with the highest priority., void push(T element, int p) Inserts the element at the back of the queue of the given priority p int size() Returns the number of elements in the queue. a) A skeleton of the class is given: public class QPQueue<T> { private static int MAXPRIORITY = 10; private LinkedQueue<T>[] priority; private int pqsize; public QPQueue() { priority = new LinkedQueue[MAXPRIORITY+1]; for(int I =0; i<= MAXPRIORITY; i++) priority[i] = new LinkedQueue<T>(); pqsize = 0; } public void push(T item, int p) { }
RA Page 1