优先队列priority_queue容器的使用方法:出队,入队,删除队首元素,判断是否为空
#include#includeusing namespace std;int main(){priority_queue pq;//入队,插入新元素;pq.push(1);pq.push(2);pq.push(3);pq.push(9);//返回队列中元素数目;cout//所有元素出队,删除所有元素while (p
·
#include <queue>
#include <iostream>
using namespace std;
int main()
{
priority_queue<int> pq;
//入队,插入新元素;
pq.push(1);
pq.push(2);
pq.push(3);
pq.push(9);
//返回队列中元素数目;
cout << pq.size() << endl;
//所有元素出队,删除所有元素
while (pq.empty() != true)
{
//读取当前队首元素
cout << pq.top() << " ";
//出队,删除队首元素
pq.pop();
}
cout << endl;
cin.get();
return 0;
}
#include <iostream>
using namespace std;
int main()
{
priority_queue<int> pq;
//入队,插入新元素;
pq.push(1);
pq.push(2);
pq.push(3);
pq.push(9);
//返回队列中元素数目;
cout << pq.size() << endl;
//所有元素出队,删除所有元素
while (pq.empty() != true)
{
//读取当前队首元素
cout << pq.top() << " ";
//出队,删除队首元素
pq.pop();
}
cout << endl;
cin.get();
return 0;
}
更多推荐
已为社区贡献4条内容
所有评论(0)