Point オブジェクト (それぞれ x、y プロパティを持つ) のリストがあり、左端と右端のポイントを見つけたいと考えています。私はfind_ifでそれをやろうとしてきましたが、コンパレータインスタンスを渡すことができないように見えるので、その方法がわかりません。find_if は行く方法ですか?そうではないようです。<algorithm>
それで、これを達成するためのアルゴリズムはありますか?
前もって感謝します。
#include <iostream>
#include <list>
#include <algorithm>
using namespace std;
typedef struct Point{
float x;
float y;
} Point;
bool left(Point& p1,Point& p2)
{
return p1.x < p2.x;
}
int main(){
Point p1 ={-1,0};
Point p2 ={1,0};
Point p3 ={5,0};
Point p4 ={7,0};
list <Point> points;
points.push_back(p1);
points.push_back(p2);
points.push_back(p3);
points.push_back(p4);
//Should return an interator to p1.
find_if(points.begin(),points.end(),left);
return 0;
}