The Priority. Queue ADT As an ADT, a priority queus P supports the following functions: • • • • isPQueueEmpty(): returns true if pqueue is empty otherwise false size(): Return the number of elements in P. smpty(): Return true if P is empty and false otherwise. insert(e): Insert a new element e into, P. ● min): Return a reference to an element of P with the smallest associated kex value (but do not remove it); an error condition occurs if the priority queue is empty. • removeMin(): Remove from P the element referenced by min(); an error condition occurs if the priority queue is empty. Example: The following table shows a series of operations and their effects on an initially empty priority queue P. Each element consists of an integer, which we assume to be sorted according to the natural ordering of the integers. Note that each call to min returns a reference to an entry in the queue, not the actual value. Although the "Priority. Queue" column shows the items in sorted order, the priority queus need not store elements in this order.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter18: Stacks And Queues
Section: Chapter Questions
Problem 21SA
icon
Related questions
Question
The Priority. Queue ADT
As an ADT, a priority queue P supports the following functions:
•
isPQueueEmpty(): returns true if pqueue is empty otherwise false
size(): Return the number of elements in P.
empty(): Return true if P is empty and false otherwise.
Example: The following table shows a series of operations and their effects on an initially
empty priority queue P. Each element consists of an integer. which we assume to be sorted
according to the natural ordering of the integers. Note that
insert(e): Insert a new element e into P.
min(): Return a reference to an element of P with the smallest associated kex value
(but do not remove it); an error condition occurs if the priority queue is empty.
removeMin): Remove from P the element referenced by min(); an error condition
occurs if the priority queue is empty.
each call to min returns a reference to an entry in the queue, not the actual value. Although the
"Priority Queue" column shows the items in sorted order, the priority queue need not store.
elements in this order.
Operation Return
insert(5)
insert(9)
insert(2)
insert(7)
min()
size()
min()
[2]
removeMin [2]
3
[5]
removeMin [5]
removeMin [7]
removeMin [9]
}
Priority Queue
{5}
{5,9}
{2,5,9}
{2,5,7,9}
{2,5,7,9}
{5,7,9}
{5,7,9}
{5,7,9}
{7,9}
{9}
{}
empty()
true
removeMin invalid operation {}
You may use following interface to implement PriorityQueus
public interface PriorityQueue{
public int peek():
public void insert(int item);
public int deletMin();
public int size();
Transcribed Image Text:The Priority. Queue ADT As an ADT, a priority queue P supports the following functions: • isPQueueEmpty(): returns true if pqueue is empty otherwise false size(): Return the number of elements in P. empty(): Return true if P is empty and false otherwise. Example: The following table shows a series of operations and their effects on an initially empty priority queue P. Each element consists of an integer. which we assume to be sorted according to the natural ordering of the integers. Note that insert(e): Insert a new element e into P. min(): Return a reference to an element of P with the smallest associated kex value (but do not remove it); an error condition occurs if the priority queue is empty. removeMin): Remove from P the element referenced by min(); an error condition occurs if the priority queue is empty. each call to min returns a reference to an entry in the queue, not the actual value. Although the "Priority Queue" column shows the items in sorted order, the priority queue need not store. elements in this order. Operation Return insert(5) insert(9) insert(2) insert(7) min() size() min() [2] removeMin [2] 3 [5] removeMin [5] removeMin [7] removeMin [9] } Priority Queue {5} {5,9} {2,5,9} {2,5,7,9} {2,5,7,9} {5,7,9} {5,7,9} {5,7,9} {7,9} {9} {} empty() true removeMin invalid operation {} You may use following interface to implement PriorityQueus public interface PriorityQueue{ public int peek(): public void insert(int item); public int deletMin(); public int size();
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Stack
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning