【发布时间】:2019-05-04 10:16:05
【问题描述】:
我有一个包含点向量的向量是一个具有 x 和 y 坐标的类。我基本上必须从我的向量中删除所有排列和子集。为此,我使用算法包括和 is_permutation
我已经重载了 '==' 运算符,我们需要它是有道理的。但是除非我重载'
这是我的点课:
class Point{
private:
int x;
int y;
public:
Point(){
x=0;
y=0;
}
Point(int xx, int yy){
x=xx;
y=yy;
}
double getSlope(Point p){
if(this->x!=p.x && this->y!=p.y){
return (double)(double(this->y-p.y)/double(this->x-p.x));
}else if(this->x==p.x){
return INT_MAX;
}else{
return INT_MIN;
}
}
void print(){
cout<<"(" <<x<<","<<y<<")";
}
bool operator == (Point &p){
if(this->x==p.x && this->y==p.y )
return true;
else
return false;
}
bool operator < (Point &p){
cout<<"\nin the < operator\n";
if(this->x < p.x && this->y < p.y )
return true;
else
return false;
}
};
这是一个接收点的临时向量的函数 并将其与 vector> 进行比较以删除排列。 这些点是从文件中获取的,因此我们只在通过检查时才将其添加到向量中的点
bool check(PointVector temp, vector<PointVector> pointArrays ){
for(int i =0 ; i < pointArrays.size(); i++){
if(is_permutation(pointArrays[i].begin(),pointArrays[i].end(),temp.begin())){
return false;
}else if(includes(pointArrays[i].begin(),pointArrays[i].end(),temp.begin(),temp.end())){
return false;
}else if(includes(temp.begin(),temp.end(),pointArrays[i].begin(),pointArrays[i].end())){
pointArrays[i].swap(temp);
return false;
}
}
return true;
}
点向量是vector<points>; 的类型定义
【问题讨论】:
-
不重载
<会出现什么错误?