Code : Max Priority Queue

 

Implement the class for Max Priority Queue which includes following functions -

1. getSize -

Return the size of priority queue i.e. number of elements present in the priority queue.

2. isEmpty -

Check if priority queue is empty or not. Return true or false accordingly.

3. insert -

Given an element, insert that element in the priority queue at the correct position.

4. getMax -

Return the maximum element present in the priority queue without deleting. Return -Infinity if priority queue is empty.

5. removeMax -

Delete and return the maximum element present in the priority queue. Return -Infinity if priority queue is empty.

Note : main function is given for your reference which we are using internally to test the class.









class PriorityQueue {
// Declare the data members here

public:
PriorityQueue() {
// Implement the constructor here
}

/**************** Implement all the public functions here ***************/

void insert(int element) {
// Implement the insert() function here
}

int getMax() {
// Implement the getMax() function here
}

int removeMax() {
// Implement the removeMax() function here
return pq.
}

int getSize() {
return pq.size();
// Implement the getSize() function here
}

bool isEmpty() {
if(pq.size()==0) return 0;
else return true;
// Implement the isEmpty() function here
}
};

Comments

Popular posts from this blog

Code : All connected components

Coding Ninjas