priority_queue例子

#include<iostream>
#include<queue>
using namespace std;
class node{
public:
	int key;
	int value;
	bool operator()(node a,node b){
		return a.value>b.value;
		}
	node(){}
	node(int key,int value):key(key),value(value){}
};
int main(){
	node n1(1,2);
	node n2(2,3);
	node n3(3,0);
	node n4(4,9);
	node n5(5,1);
	node n6(6,6);
	priority_queue<node,vector<node>,node>myque;
	myque.push(n1);
	myque.push(n2);
	myque.push(n3);
	myque.push(n4);
	myque.push(n5);
	myque.push(n6);
	while(!myque.empty()){
		cout<<myque.top().key<<" "<<myque.top().value<<endl;	
		myque.pop();
	}
	
}


你可能感兴趣的:(n2)