A priority queue is a queue where a numeric priority is asso

A priority queue is a queue where a numeric priority is associated with each element. Access to elements that have been inserted into the queue is limited to inspection and removal of the elements with smallest and largest priority only. A priority queue may have multiple items that are of equal priority. By “bounded”, it is meant that the priority queue has a maximum capacity specified when it is created, and it can never contain more than that number of items. Your specification must specify the following operations:

newPriorityQueue: make a new queue

insert: inserts an element with a certain priority

isEmpty: test if the queue is empty

isFull: test if the queue is full

maxItem: obtain the item in the queue with the highest priority

minItem: obtain the item in the queue with the lowest priority

deleteMax: remove from the queue the item with the highest priority

deleteAllMax: remove from the queue all items that are tied for the highest priority

deleteMin: remove from the queue the item with the lowest priority frequency: obtain the number of times a certain item occurs in the queue (with any priority)

showing it in the form of sets signatures , preconditions and semantics thanks

Solution

newPriorityQueue: make a new queue

Priority_queue<P,I> Q(int(*cmp)(p,p)):

creates an instance Q of priority_queue<P,I> based on the given order defined by the compare function cmp and initializes it with the empty priority queue.

Precondition cmp must define a given order on P.

insert: inserts an element with a certain priority

priorityqueue_item Q.insert(P x,I i) :Adding an item x with priority with I into queue.

isEmpty: test if the queue is empty

bool Q.empty()   returns queue is empty ,false other wise.

isFull: test if the queue is full

bool Q.isFull() returns queue is full ,false other wise.

maxItem: obtain the item in the queue with the highest priority

priorityqueue_item Q.maxItem() :returning item in Q with max priority I

Precondition: Queue is not empty

minItem: obtain the item in the queue with the lowest priority

priorityqueue_item Q.minItem() :returning item in Q with minimum priority I

Precondition: Queue is not empty

deleteMax: remove from the queue the item with the highest priority

P Q. deleteMax() : deletes item with maximum priority in priority queue and returning priority.

Precondition: Queue is not empty

deleteAllMax: remove from the queue all items that are tied for the highest priority

priorityqueue_item[]   Q. deleteAllMax() : deletes item or items with maximum priority in priority queue and returning   list of items that can be deleted.

Precondition: Queue is not empty

deleteMin: remove from the queue the item with the lowest priority frequency: obtain the number of times a certain item occurs in the queue (with any priori

P Q. deleteMn() : deletes item with minimum priority in priority queue and returning priority.

Precondition: Queue is not empty

A priority queue is a queue where a numeric priority is associated with each element. Access to elements that have been inserted into the queue is limited to in
A priority queue is a queue where a numeric priority is associated with each element. Access to elements that have been inserted into the queue is limited to in

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site