A New Data Structure: The Priority Queue
A priority queue is a data structure that allows insertion and deletion of elements. Each element in a priority queue has a unique integer priority. Unlike the queues of Chapter 16, items are deleted from a priority queue in order of priority; the element with highest priority is removed first. A waiting line in a bakery models a priority queue. As a customer enters the bakery he/she takes a ticket. The customer with the lowest-numbered ticket is served first. The lowest-numbered ticket has the highest priority.
A priority queue should support the following methods:
• void insert(E data, int priority);
• E delete();
• boolean contains(E data);
a. Design a PriorityQueue class using one (or more) of the Collection classes.
b. Which methods perform in constant time, that is, the time is independent of the number of elements in the priority queue? Explain your answer.
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.