C++ priorityqueue知识总结


c++模板中关于priorityqueue的声明在queue头文件中,因此使用时要#include

Construct

重载两种形式

priority_queue<int>;
priority_queue<valuetype,container,bool compare>;

Feature

  1. based on container;
  2. ‘compare’ is a functor;

example:

class g {
public:
    bool operator() (int a,int b){
        return a > b;
    }
};
 priority_queue<int,vector<int>, g  > a;
   for (int i = 0; i < 10; i++)a.emplace(i);
    while (!a.empty()) {
        cout << a.top(); a.pop();
    }

Iterator

try and failed(dog).

Capaticy

size();
empty();

Modify

push();
pop();
emplace();
top();

end;

猜你喜欢

转载自blog.csdn.net/qq_36389986/article/details/111985986