I suggest you to go through the following program step by step to understand easily and that can helpful for you to gather the knowledge of the unique() function in the C++ coding :
Code:
#include <iostream>
#include <algoritrhm>
#include <vector>
using namespace std;
bool mfnctn (int i, int j)
{
return (i==j);
}
int main ()
{
int mit[] = {10,20,20,20,30,30,20,20,10};
vector<int> mvctor (mit,mit+9);
vector<int>::itrerator itr;
itr = unique (mvctor.begin(), mvctor.end());
mvctor.resize( itr - mvctor.begin() );
unique (mvctor.begin(), mvctor.end(), mfnctn);
cout << "mvctor contains:";
for (itr=mvctor.begin(); itr!=mvctor.end(); ++itr)
cout << " " << *itr;
cout << endl;
return 0;
}
Output:
Code:
mvctor contains: 10 20 30 20 10
Bookmarks