#include "algostuff.hpp"
using namespace std;
void printCollection(const list<int>& l)
{
 PRINT_ELEMENTS(l);
}
bool lessForCollection(const list<int>& l1,const list<int>& l2)
{
    return lexicographical_compare(l1.begin(),l1.end(),l2.begin(),l2.end());
}
int main()
{
 list<int >c1,c2,c3,c4;
 INSERT_ELEMENTS(c1,1,5);
 c4=c3=c2=c1;
 c1.push_back(7);
 c3.push_back(2);
 c3.push_back(0);
 c4.push_back(2);
 vector<list<int> >cc;//两个>不能连着写
 cc.push_back(c1);
 cc.push_back(c2);
 cc.push_back(c3);
 cc.push_back(c4);
 cc.push_back(c3);
 cc.push_back(c1);
 cc.push_back(c4);
 cc.push_back(c2);

 for_each(cc.begin(),cc.end(),printCollection);
 cout<<endl;
 
 sort(cc.begin(),cc.end(),lessForCollection);
 for_each(cc.begin(),cc.end(),printCollection);
}

///////////////////////////////////////////////////////////////////

output:

1 2 3 4 5 7
1 2 3 4 5
1 2 3 4 5 2 0
1 2 3 4 5 2
1 2 3 4 5 2 0
1 2 3 4 5 7
1 2 3 4 5 2
1 2 3 4 5

1 2 3 4 5
1 2 3 4 5
1 2 3 4 5 2
1 2 3 4 5 2
1 2 3 4 5 2 0
1 2 3 4 5 2 0
1 2 3 4 5 7
1 2 3 4 5 7
Press any key to continue

 

字典次序意味着:

如果两元素不相等,则这两个元素的比较结果就是整个序列的比较结果。

如果两序列的元素数量不同,则元素较少的那个序列小于另一序列,所以,如果第一序列的元素数量较少,比较结果返回true

如果两序列都没有更多的元素可作比较,则这两个序列相等,整个比较结果返回false

 

posted on 2010-04-17 20:45  蓝牙  阅读(931)  评论(0编辑  收藏  举报