2021-03-07 C++常用回调函数less和greater——在sort和priority的应用

priority_queue回调函数详解

//升序队列
priority_queue <int,vector<int>,greater<int> > q;
//降序队列
priority_queue <int,vector<int>,less<int> >q;

//greater和less是std实现的两个仿函数(就是使一个类的使用看上去像一个函数。其实现就是类中实现一个operator(),这个类就有了类似函数的行为,就是一个仿函数类了)

sort第三个参数——回调函数想详解

sort(A,A+100,greater<int>());//降序排列
sort(A,A+100,less<int>());//升序排列

猜你喜欢

转载自blog.csdn.net/sddxszl/article/details/114476719