一、lexicographical_compare
头文件algorithm
default (1)
template <class InputIterator1, class InputIterator2>
bool lexicographical_compare (InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2);
custom (2)
template <class InputIterator1, class InputIterator2, class Compare>
bool lexicographical_compare (InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
Compare comp);
字典小于比较
如果范围[first1,last1]按字典顺序比较范围[first2,last2],则返回true。
字典比较是一种比较,通常用于在字典中按字母顺序对单词进行排序; 它涉及顺序地比较两个范围中具有相同位置的元素彼此之间的比较,直到一个元素不等同于另一个元素。 比较这些第一非匹配元素的结果是词典比较的结果。
如果两个序列比较相等直到其中一个结束,则较短的序列按字典顺序小于较长的序列。
使用operator <作为第一个版本比较元素,comp作为第二个版本。 如果(!(a <b)&&!(b <a))或if(!comp(a,b)&&!comp(b,a)),则认为两个元素a和b是等价的。
此函数模板的行为等效于:
template <class InputIterator1, class InputIterator2>
bool lexicographical_compare (InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2)
{
while (first1!=last1)
{
if (first2==last2 || *first2<*first1) return false;
else if (*first1<*first2) return true;
++first1; ++first