I'm wondering why does the following code return the element with 10 as top element
class mycomparison
{
public:
bool operator() (pair<int, Node*> e1, pair<int, Node*> e2) const {
return e1.first < e2.first;
};
};
priority_queue<pair<int, Node*>, vector<pair<int, Node*>>, mycomparison> queue;
queue.push(make_pair(4, &root));
queue.push(make_pair(10, &root));
auto var = queue.top();
Shouldn't it return the 4 element?
The C++ priority queue is a max -heap; the largest element is on top
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.