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_Stl Algorithm - Fatal编程技术网

Sorting 对曲线向量中的元素进行排序

Sorting 对曲线向量中的元素进行排序,sorting,c++11,stl-algorithm,Sorting,C++11,Stl Algorithm,我有一个类点,它代表x和y坐标和 对有两点、起点和终点的曲线进行分类 class point { public: double x{0.0}, y{0.0}; //......... } class curve { public: point start, end; //......... } 我有一个曲线向量,需要排序。 一条曲线的起点等于另一条曲线的终点。 输出曲线(将一条曲线保持在另一条曲线之后)可以是开放曲线或闭合曲线(始终是连续曲线) 具有大量回路和

我有一个类点,它代表x和y坐标和 对有两点、起点和终点的曲线进行分类

class point {
public:
    double x{0.0}, y{0.0};
    //.........
}

class curve {
public:
    point start, end;
    //.........
}
我有一个曲线向量,需要排序。 一条曲线的起点等于另一条曲线的终点。 输出曲线(将一条曲线保持在另一条曲线之后)可以是开放曲线或闭合曲线(始终是连续曲线)

具有大量回路和2/3矢量的当前逻辑。。
是否有一种方法可以使用标准算法(c++11)实现相同的功能。

假设向量的第一个元素是路径的起点,并且只有一个解决方案,以下几行将完成此工作:

bool operator!=(point& a,point& b) {
    return !(a.x == b.x && b.y == a.y);
}

bool operator==(point& a, point& b) {
    return (a.x == b.x && b.y == a.y);
}

void order(std::vector<curve>& vin) {
    auto it = vin.begin();
    auto end = vin.end();
    while (it+1 != end) {
        if (it->end != (it + 1)->start) {
            std::swap(*(it + 1), *std::find_if(it + 2, end, [it](curve& c){ return c.start == it->end ;  }));
        }
        ++it ;
    }
}

可能您需要考虑操作员
=
双精度=。也可以用函数替换它们

这不是排序问题,而是排序问题。您需要知道如何找到排序顺序。事实上,您是对的,我将再次查看并测试您的答案,因为我发现这是一个有趣的问题!
bool is_the_beginning(curve& c) {
    if ( ... )  return true;
    else return false ;
}
std::swap(*it, *std::find_if(it+1, end, is_the_beginning ) ) ;