STL之优先级队列priority_queue
1.简介
- 最大值优先级队列、最小值优先级队列
- 优先级队列适配器 STL priority_queue
- 用来开发一些特殊的应用
2.示例代码
int main(void)
{
priority_queue<int> p1;
priority_queue<int, vector<int>, less<int>> p2;
priority_queue<int, vector<int>, greater<int> > p3;
p1.push(2);
p1.push(4);
p1.push(6);
p1.push(1);
p1.push(3);
p1.push(4);
cout << "头元素:" << p1.top() << endl;
cout << "队列大小:" << p1.size() << endl;
while (p1.size()>0)
{
cout << p1.top() << "\t";
p1.pop();
}
cout << endl;
cout << "测试 最小值优先级队列 " << endl;
p3.push(33);
p3.push(11);
p3.push(55);
p3.push(22);
cout << " 最小值优先级队列 队头元素:" << p3.top() << endl;
cout << " 最小值优先级队列 队列的大小:" << p3.size() << endl;
while (p3.size() > 0)
{
cout << p3.top() << " ";
p3.pop();
}
return 0;
}