#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
using namespace std;
int main()
{
int source[] = { 1, 4, 4, 6, 1, 2, 2, 3, 1, 6, 6, 6, 5, 7,
5, 4, 4 };
int sourceNum = sizeof(source)/sizeof(source[0]);
vector<int> coll;
copy (source, source+sourceNum, //source
back_inserter(coll)) ; //destination
copy (coll.begin(), coll.end(), ostream_iterator<int>(cout," "));
cout << "\n\n";
sort(coll.begin(),coll.end());
vector<int> :: iterator pos;
pos = unique (coll.begin(), coll.end());
copy (coll.begin(), coll.end(), ostream_iterator<int>(cout," "));
cout << "\n\n";
copy (coll.begin(), pos, ostream_iterator<int>(cout," "));
cout << "\n\n";
copy (source, source+sourceNum,coll.begin());
copy (coll.begin(), coll.end(),ostream_iterator<int>(cout," "));
cout << "\n\n";
//remove elements if there was a previous greater element
coll.erase (unique (coll.begin(), coll.end(),greater<int>()), coll.end());
copy (coll.begin(), coll.end(), ostream_iterator<int>(cout," "));
cout << "\n\n";
}
----------------------------------------
但是当要比较的数为计算所的的一个double,不能用sort和unique,怎么办?有没有好的办法啊!谢谢!
比如要比较的vector是从屏幕是得到的点的x坐标!坐标是通过鼠标时时得到!
要得到所有的不同的点的x坐标?
(可以用近似的算法)