// // Created by PC on 25-8-9. // #ifndef MAXPRIORITYQUEUEREALISE_H #define MAXPRIORITYQUEUEREALISE_H #include "maxPriorityQueue.h" #include template class maxPriorityQueueRealise : public maxPriorityQueue { private: std::vector> queue; //T是元素,int是优先等级 int qsize; public: maxPriorityQueueRealise() : qsize(0) {} bool empty() const {return qsize == 0;} int size() const {return qsize;} T& top(); void pop(); void push(const std::pair& x); }; template T& maxPriorityQueueRealise::top() { int max = -1; int pos = 0; int index = 0; for ( std::pair x : queue ) { if (x.second > max) { max = x.second; pos = index; } index++; } return queue[pos].first; } template void maxPriorityQueueRealise::pop() { int max = -1; int pos = 0; int index = 0; for ( std::pair x : queue ) { if (x.second > max) { max = x.second; pos = index; } index++; } queue.erase(queue.begin() + pos); } template void maxPriorityQueueRealise::push(const std::pair& x) { queue.push_back(x); } #endif //MAXPRIORITYQUEUEREALISE_H