0% found this document useful (0 votes)
35 views1 page

Jvyxmv

This document provides instructions for implementing a priority queue data structure using an array of queues. It describes: 1) Storing elements in queues based on their priority, with each index of the priority array corresponding to a different priority level. The highest priority queue will be the first non-empty one when removing elements. 2) A skeleton class called QPQueue is given to implement the priority queue using an array of linked queues. Methods like isEmpty(), push(), pop(), peek() and size() need to be completed based on this design. 3) A test program is referenced to check if the priority queue implementation works correctly.

Uploaded by

Syuk Pro
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views1 page

Jvyxmv

This document provides instructions for implementing a priority queue data structure using an array of queues. It describes: 1) Storing elements in queues based on their priority, with each index of the priority array corresponding to a different priority level. The highest priority queue will be the first non-empty one when removing elements. 2) A skeleton class called QPQueue is given to implement the priority queue using an array of linked queues. Methods like isEmpty(), push(), pop(), peek() and size() need to be completed based on this design. 3) A test program is referenced to check if the priority queue implementation works correctly.

Uploaded by

Syuk Pro
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

WXES1115/WXES1117 Lab 9

Sem. 1, 2011/2012

WXES1115/WXES1117 Data Structures Lab 9 chapter 15


1. You can implement a priority queue by allocating an array called priority with

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

You might also like