我正在构建一个结构列表,但我不知道如何杀死重复元素。 - 这里的结构是Point {x,y}。主要程序为 ,我放了一些样本点。我希望结果是 1 2,0 2,1 3,3 5,4 5(重复2 0删除)删除CPP中的副本
struct Point{
int x;
int y;
Point(int inX, int inY) : x(inX), y(inY) {}
};
int main()
{
list<Point> mst;
Point temp(0, 2);
mst.push_back(temp);
Point temp2(1, 2);
mst.push_back(temp2);
Point temp3(0, 2);
mst.push_back(temp3);
Point temp4(1, 3);
mst.push_back(temp4);
Point temp5(3, 5);
mst.push_back(temp5);
Point temp6(4, 5);
mst.push_back(temp6);
for (list<Point>::iterator out = mst.begin(); out != mst.end();++out) {
cout << (*out).x << " " << (*out).y << endl;
}
// kill duplicate (I DONT KNOW HOW)
for (list<Point>::iterator out = mst.begin(); out != mst.end();++out) {
cout << (*out).x << " " << (*out).y << endl;
}
return 0;
}
`
的可能的复制[什么是删除重复和排序向量的最有效方法是什么?( http://stackoverflow.com/questions/1041620/whats-the-most-efficient-way-to-erase-duplicates-and-sort-a-vector) – iksemyonov