Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/133.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
C++ 如何使线被关闭,有点吗?(阵列中)_C++_Arrays_Sorting_Loops - Fatal编程技术网

C++ 如何使线被关闭,有点吗?(阵列中)

C++ 如何使线被关闭,有点吗?(阵列中),c++,arrays,sorting,loops,C++,Arrays,Sorting,Loops,我有个问题,我需要关闭线路,例如: 我在控制台中输入以下内容: 4 0 0 1 1 1 0 0 1 它必须像这样返回: 0 0 0 1 1 1 1 0 不是这样的: 0 0 0 1 1 0 1 1 换言之: 我输入点数,然后输入coord_x和coord_y,然后我需要对它们进行排序,并将其关闭 这是密码 struct Point { int coordX; int coordY; }; for (int i = 1; i < sizeOfMasPo

我有个问题,我需要关闭线路,例如:

我在控制台中输入以下内容:

 4
 0 0
 1 1
 1 0
 0 1
它必须像这样返回:

 0 0
 0 1
 1 1
 1 0
不是这样的:

 0 0
 0 1
 1 0
 1 1
换言之:

我输入点数,然后输入coord_x和coord_y,然后我需要对它们进行排序,并将其关闭

这是密码

 struct Point {
int coordX;
int coordY;
};


 for (int i = 1; i < sizeOfMasPoint; ++i) {
    Point temp = masPoint[i];
    bool is_Sorted = 0;
    int j = i;
    for (; j > 0; --j) {
        if (temp.coordX > masPoint[j - 1].coordX) {
            is_Sorted = 1;
        } else {
            if (temp.coordX < masPoint[j - 1].coordX) {
                masPoint[j] = masPoint[j - 1];
            } else {
                if (temp.coordY >= masPoint[j - 1].coordY) {
                    is_Sorted = 1;
                } else {
                    masPoint[j] = masPoint[j - 1];
                }
            }
        }
        if (is_Sorted == 1)
            break;
    }
    masPoint[j] = temp;
}
我需要把它关上…我不知道怎么关


提前谢谢你

请给出
的定义,使其关闭
,这不是一个官方术语,我无法从question@IvayloStrandjev你看,最后一个点必须在直线的起点,所以它必须有一个点…如果起点是0,那么最后一个点必须是1 0或0 1,或者0似乎您想要构建一组points@IvayloStrandjev,不,它不是,我需要使线的末端更靠近起点,它不是凸包,因为我需要使用所有点(它是一条线)来“使其闭合”,你只需要在最后重复第一个点,所以这条线在它开始的地方结束。。。更改点的顺序不会“使其闭合”-它只会导致穿过同一组点的不同(多边形)线。
 0 0
 0 1
 1 0
 1 1