C++ 如何使min_元素捕获具有最小值的所有点?
我正在写一个程序来计算凸包的周长,需要在一组数据点中找到最低的y坐标。我正在使用C++ 如何使min_元素捕获具有最小值的所有点?,c++,algorithm,grahams-scan,C++,Algorithm,Grahams Scan,我正在写一个程序来计算凸包的周长,需要在一组数据点中找到最低的y坐标。我正在使用std::min_元素(vector.begin(),vector.end())和一个重载的那么,像这样吗?(要替换现有的操作符或只需更改操作符如果您与cord对象类结为夫妻,请在操作符中使用。您是否试图为最小的y找到最小的x,或者用最小的y找到所有点?您的标题指向后者,但您的问题是b。)奥迪指出了前者。 struct cord{ cord():x(0),y(0){} int x,y;
std::min_元素(vector.begin(),vector.end())
和一个重载的那么,像这样吗?(要替换现有的操作符或只需更改操作符如果您与cord
对象类结为夫妻,请在操作符中使用。您是否试图为最小的y
找到最小的x
,或者用最小的y
找到所有点?您的标题指向后者,但您的问题是b。)奥迪指出了前者。
struct cord{
cord():x(0),y(0){}
int x,y;
bool operator<(const cord &p) const { return y < p.y; }
};
typedef std::vector<cord>::iterator vecIter;
vecIter lowestPoint =
std::min_element(points.begin(), points.end());
std::cout << "the lowest point of the data set is: " << "(" <<
lowestPoint->x << "," << lowestPoint->y << ")" << std::endl;
bool operator<(const cord &p) const
{
if (y != p.y)
return y < p.y;
else
return x < p.x;
}