Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sorting 按到特定点的距离对点进行排序_Sorting_C++11 - Fatal编程技术网

Sorting 按到特定点的距离对点进行排序

Sorting 按到特定点的距离对点进行排序,sorting,c++11,Sorting,C++11,我试着根据到特定点的距离对很多点进行排序。 所以,我决定使用std::sort,但我找不到给Comp函数第三个参数的方法。 我想象Python中的lambda函数类似于lambda pnt1,pnt2:compare(pnt1,pnt2,myPoint),但我找不到它。类似于: int distance(Point const&, Point const&); // Returns distance between points. Point p{x, y}; std::vec

我试着根据到特定点的距离对很多点进行排序。 所以,我决定使用std::sort,但我找不到给Comp函数第三个参数的方法。 我想象Python中的lambda函数类似于
lambda pnt1,pnt2:compare(pnt1,pnt2,myPoint)
,但我找不到它。

类似于:

int distance(Point const&, Point const&); // Returns distance between points.

Point p{x, y};
std::vector<Point> points{...};
std::sort(points.begin(), points.end(), [p](Point const& a, Point const& b) {
    return distance(a, p) < distance(b, p);
});
int距离(点常数&,点常数&);//返回点之间的距离。
点p{x,y};
std::向量点{…};
排序(points.begin()、points.end()、[p](点常量和a、点常量和b){
返回距离(a,p)<距离(b,p);
});
类似于:

int distance(Point const&, Point const&); // Returns distance between points.

Point p{x, y};
std::vector<Point> points{...};
std::sort(points.begin(), points.end(), [p](Point const& a, Point const& b) {
    return distance(a, p) < distance(b, p);
});
int距离(点常数&,点常数&);//返回点之间的距离。
点p{x,y};
std::向量点{…};
排序(points.begin()、points.end()、[p](点常量和a、点常量和b){
返回距离(a,p)<距离(b,p);
});

这个代码可能会帮助你:Google“STD::排序谓词例子”找到了很多例子。我不熟悉C++语法。你的一切对我都很有用。感谢这个答案可能会帮助你:Google“STD::排序谓词例子”找到了很多例子。我不熟悉C++语法。你的一切对我都很有用。谢谢