一. 去除重复的元素
1.
STL里有现成的算法.
sort和unique
根据你这个问题只要定义两个算子就行了.
C/C++ code
struct Less : public binary_functin
{
bool operator()( two_nums p1, two_nums p2){ return p1 < p2; }
}
struct Unique : public binary_functin
{
bool operator()( two_nums p1, two_nums p2){ return p1.b == p2.b && p1.a != p2.a; }
}
sort( data.begin(), data.end(), Less );
unique( data.begin(), data.end(), Unique );
2
2.1,读入 vector < two_nums> reads
2.2 , 对 vector 按 b排序
2.3,写一个泛函数,格式
struct comp
{
bool operator() (const two_nums &r1, const two_nums &r2) const
{
return r1.SStart < r2.SStart ;
}
};
2.4, vector :: iterator it;
it = unique( reads.begin(),reads.end(), comp());
reads.resize( it - reads.begin());
阅读(871) | 评论(0) | 转发(0) |