您当前的位置: 首页 >  算法

我什么都布吉岛

暂无认证

  • 1浏览

    0关注

    292博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

STL stable_sort算法的第三个参数

我什么都布吉岛 发布时间:2020-07-10 22:38:51 ,浏览量:1

stable_sort定义
template 
  void stable_sort ( RandomAccessIterator first, RandomAccessIterator last );

template 
  void stable_sort ( RandomAccessIterator first, RandomAccessIterator last,
                     Compare comp );

第三个参数comp: 它是一个二元函数,返回一个bool值。他决定了第一个元素是否在第二个前面,简单来说,如果返回true顺序就是参数顺序,反之,则是参数反序。 Binary function that accepts two elements in the range as arguments, and returns a value convertible to bool. The value returned indicates whether the element passed as first argument is considered to go before the second in the specific strict weak ordering it defines. The function shall not modify any of its arguments. This can either be a function pointer or a function object.

用法
#include 
#include 
#include 
#include 

using namespace std;

struct student
{
	student(string name ,int id,double stature):m_name(name),m_id(id),m_stature(stature){}
	string m_name;	     //名字
	int m_id;            //学号
	double m_stature;    //身高

};

//student对象从高到低排列
bool comp(student s1, student s2)
{
	return s2.m_stature            
关注
打赏
1658157489
查看更多评论
0.0412s