关于STL的排序,和比较参数cmp

stable_sort

template <class RandomAccessIterator> void stable_sort ( RandomAccessIterator first, RandomAccessIterator last );

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

Sort elements preserving order of equivalents

Sorts the elements in the range  [first,last) into ascending order, like  sort, but  stable_sort grants that the relative order of the elements with equivalent values is preserved.

The elements are compared using  operator< for the first version, and  comp for the second.

Parameters

first, last
  [first,last)
comp
Comparison function object that, taking two values of the same type than those contained in the range, returns  true  if the first argument goes before the second argument in the specific strict weak ordering(严格偏序) it defines, and false otherwise.

bool cmp(Record a,Record b);
默认是增序,即若a.key < b.key, return true,按增序排列。
若a.key > b.key return true,则实际是按减序排列的
也可以定义相等时的大小比较来定义第二阶的排序

 
1046. Plane Spotting
 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值