我实现了一个二进制搜索这样的:C++ STL二进制搜索(LOWER_BOUND,UPPER_BOUND)
typedef std::vector<Cell>::iterator CellVectorIterator;
typedef struct _Point {
char x,y;
} CoordinatePoint;
typedef struct _Cell {
...
CoordinatePoint coordinates;
} Cell;
struct CellEqualityByCoordinates
{
bool
operator()(const Cell& cell1, const Cell& cell2) const
{ return cell1.coordinates.x == cell2.coordinates.x && cell1.coordinates.y == cell2.coordinates.y; }
};
CellVectorIterator FindCellByCoordinates (CellVectorIterator first, CellVectorIterator last, const Cell &val)
{
return std::upper_bound(first, last, val, CellEqualityByCoordinates());
}
不过,这并不总能找到一个值。
这是什么问题?
http://stackoverflow.com/questions/18958015/stdsort-giving-very-strange-results/18958178#18958178 – billz