list 容器 排序函数

来源:互联网 发布:数据安全法律法规 编辑:程序博客网 时间:2024/05/13 22:30

转自 http://blog.csdn.net/shuilan0066/article/details/4670112


list 容器 排序函数



struct Point
{
 double x,y,z;
};
 
 
制定排序规则,重载()运算符:
 
(一) 按x值的大小 进行升序排序
 
class ascend_x
{
public:
 bool operator()(const Point &t1,Point &t2)
 {return t1.x<t2.x;}
};
 
 
 
(二) 按y值的大小 进行升序排序


class ascend_y
{
public:
 bool operator()(const tag_Point &t1,tag_Point &t2)
 {return t1.y<t2.y;}
};
 
 
list<Point> list_point;
 
list_point.push_back(point);
....
....
 
 
对list_point中的元素按x进行升序排序
 
 
list_point.sort(ascend_x())  //  里面参数为ascend_x()
 
这样 list_point中的元素 就按指定的排序规则进行排序了
0 0
原创粉丝点击