以
1. 使用 #include <algorithm> 中的 sort 方法
a.
在数据结构中 重载 < 符号,
struct xx
{
bool operator<(const containername& rhs)const
{ return index<rhs.index;
}
}
使用: std;:sort(containername.begin(), containername.end);
b.
定义一个 外部方法,
bool f(const containername & lhs, const containername& rhs)
{ return lhs.index<rhs.index;
}
使用: std;:sort(containername.begin(), containername.end,f);
2. 使用函数对象 重载 () 运算符
bool operator()(const containername& lhs, const containername& rhs)
{return lhs.index<rhs.index;}
{return lhs.index<rhs.index;}
使用: std;:foreach(containername.begin(), containername.end,f);