#include <queue> //因为要使用priority_queue
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
priority_queue<double> priorities;
priorities.push(3.2);
priorities.push(9.8);
priorities.push(5.4);
while(!priorities.empty())
{
cout<<priorities.top()<<" ";
priorities.pop();
}
cout<<"\n*******************************************"<<endl;
const int SIZE=10;
int a1[]={2,8,1,50,3,100,8,9,10,2};
vector<int> v(a1,a1+SIZE);
vector<int>::iterator location;
location=find(v.begin(),v.end(),10); //找到了,返回指向找到的元素的迭代器,没找到返回v.end()这个迭代器
if(location!=v.end())
cout<<endl<<"1)"<<location-v.begin();
sort(v.begin(),v.end());
if(binary_search(v.begin(),v.end(),9)) //binary_search()函数返回的是bool
cout<<endl<<"2)"<<"9 found";
else
cout<<endl<<"2)"<<"9 not found";
return 0;
} STL中priority_queue的使用
最新推荐文章于 2025-03-07 09:34:09 发布
本文演示了如何在C++中使用优先队列(priority_queue)进行元素的插入与输出,并展示了如何利用标准模板库(STL)中的find与binary_search函数来查找向量(vector)中的元素。
976

被折叠的 条评论
为什么被折叠?



