#include <iostream>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<vector>
#define N 3
using namespace std;
struct point
{
double x;
double y;
};
int cmp(const void *a,const void *b)
{
if((*(point*)a).x==(*(point*)b).x)
return (*(point*)a).y>(*(point*)b).y?1:-1;
else if((*(point*)a).x>(*(point*)b).x) return 1;
else return -1;
}
void show_point(const point &temp)
{
cout.setf(ios::left,ios::adjustfield);
cout<<"x="<<setw(3)<<setprecision(3)<<temp.x<<",y="<<setw(3)<<temp.y<<endl;
}
int main()
{
ios::sync_with_stdio(false);//解除C中的输入输出流与C++中的兼容性
cin.tie(0);//使得利用cin和cout输入输出速度更快
cout.tie(0);
int num[]={5,2,0,4,7};
cout<<"The maximum:"<<*max_element(num,num+5)
<<", The minimum:"<<*min_element(num,num+5)<<endl;
point po[N]={{2.0,3.0},{1.0,3.2},{2.0,3.2}};
qsort(po,N,sizeof(po[0]),cmp);
for_each(po,po+N,show_point);
priority_queue< int,vector<int>,less<int> >q;
cout<<"please input some number to test priority_queue:"<<endl;
int n;
while(cin>>n)
q.push(n);
cout<<"Output:";
while(!q.empty())
{
cout<<q.top()<<" ";
q.pop();
}
cout<<endl;
return 0;
}
笔记一(关于STL中min_element,max_element,priority_queue的使用)
猜你喜欢
转载自blog.csdn.net/weixin_43871369/article/details/87925615
今日推荐
周排行