#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的使用
最新推荐文章于 2023-04-04 21:27:17 发布