sort的用法

std::sort

default (1)
template <class RandomAccessIterator>
  void sort (RandomAccessIterator first, RandomAccessIterator last);
custom (2)
template <class RandomAccessIterator, class Compare>
  void sort (RandomAccessIterator first, RandomAccessIterator last, Compare comp);
Sort elements in range
Sorts the elements in the range  [first,last) into ascending order.

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

Equivalent elements are not guaranteed to keep their original relative order (see  stable_sort).

Parameters

first, last
Random-access iterators to the initial and final positions of the sequence to be sorted. The range used is  [first,last), which contains all the elements between  first and  last, including the element pointed by  first but not the element pointed by  last.
RandomAccessIterator shall point to a type for which  swap is properly defined and which is both  move-constructible and  move-assignable.
comp
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.

//注意第三个参数的解释(我用红色标记的),大意就是如果comp返回的是true,则第一个元素就排在第二个元素前面



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值