优先队列的写法

优先队列:结构体的优先级设置

因为优先队列本质是堆

struct node{
	string name;
	int pri;
	friend bool operator < (node f1,node f2){
		return f1.pri<f2.pri;   //友元函数,写在结构体里面的,意思时价格大的优先!!!是反的 
	}
};
priority_queue<node> q;
struct node{
	string name;
	int pri;
};
//写在外面
struct cmp{
	bool operator () (node a,node b){
		return a.pri>b.pri;
	}
}; 
//定义的时候
priority_queue<node,vector<node>, cmp> q; ///greater(),换为了cmp
//如果数据庞大,那么使用引用来提高效率
const node &a 

  

猜你喜欢

转载自www.cnblogs.com/shirlybaby/p/12264467.html