priority_queue 用法
#include <iostream> #include <cstdlib> #include <queue> using namespace std; struct Node { int x, y;
bool operator<(const Node& b) const { return x > b.x; } }; int main() { priority_queue<Node> q; for( int i= 0; i< 10; ++i ) { Node n; n.x = rand(); n.y = rand(); q.push(n); } while( !q.empty() ) { cout << q.top().x << ' ' << q.top().y << endl; q.pop(); } return 0; }