# Access over 35 millionacademic & study documents

Content type
User Generated
Rating
Showing Page:
1/5
table 9.2
Solution
9.4)
#include <vector>
using namespace std;
template<typename ElementType>
class QueueItem {
private:
int k;
ElementType elem;
QueueItem *location;
public:
QueueItem(const int k=0, const ElementType&

Showing Page:
2/5
e=ElementType()): k(k), elem(e) {}
const int getQueueKey() const { return k; }
const ElementType& getElem() const { return elem; }
void setQueueKey(const int k) { k = k; }
void setElement(const ElementType& e) { elem = e; }
};
template <typename ElementType>
class PriorityQueueArr{
protected:
typedef QueueItem<ElementType> QueueItem;
public:
vector<QueueItem> A;
PriorityQueueArr(){}
int size() const {return A.size();}
bool isEmpty() const{
if(A.size() == 0)
return true;
else
return false;
}
void insertItem(int k, const ElementType& x){
if(A.size()==0){
A[0].setQueueKey(k);
A[0].setElement(x);
}

Showing Page:
3/5

End of Preview - Want to read all 5 pages?
Access Now
Unformatted Attachment Preview
About Priority Queue. Help me please table 9.2 Solution 9.4) #include using namespace std; template class QueueItem { private: int k; ElementType elem; QueueItem *location; public: QueueItem(const int k=0, const ElementType& e=ElementType()): k(k), elem(e) {} const int getQueueKey() const { return k; } const ElementType& getElem() const { return elem; } void setQueueKey(const int k) { k = k; } void setElement(const ElementType& e) { elem = e; } }; template class PriorityQueueArr{ protected: typedef QueueItem QueueItem; public: vector A; PriorityQueueArr(){} int size() const {return A.size();} bool isEmpty() const{ if(A.size() == 0) return true; else return false; } void insertItem(int k, const ElementType& x){ if(A.size()==0){ A[0].setQueueKey(k); A[0].setElement(x); } else{ A[size() - 1].setQueueKey(k); A[size() - 1].setElement(x); } } int removeMin(){ int comp = 0; if(isEmpty()) {}//throw (BlankArray); else{ int temp; int i; int min = A[0].getQueueKey(); for(i = 1; i!= A.size(); i++){ comp++; if(A[i].getQueueKey() < min){ min = A[i].getQueueKey(); temp = i; } } A[A.size()-1] = A[temp]; } return comp; } const ElementType& minimumElement(){ if(isEmpty()) {}//throw (BlankArray); else{ int temp; int i; int min = A[0].getQueueKey(); for(i = 1; i!= A.size(); i++){ if(A[i].getQueueKey() < min){ min = A[i].getQueueKey(); temp = i; } } return A[temp].getElem(); } } int minimumKey(){ int i; int min ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

### Review

Anonymous
I was struggling with this subject, and this helped me a ton!

Studypool
4.7
Indeed
4.5
Sitejabber
4.4