Tom wrote:
How can you delete doubles of an element in a vector, all elements
check and then delete the extra ones that are in the list.
If you are willing to sort the vector then the following works well.
#include <vector>
#include <iterator>
#include <algorithm>
#include <iostream>
int main ( ) {
// Initialise vector
int list[] = { 1,2,3,4,5,4,3,2,1,2,3,4,5 };
std::vector<int> a ( list, list + sizeof(list)/sizeof(int) );
// Print contents
std::copy ( a.begin(), a.end(),
std::ostream_iterator<int>(std::cout," "));
std::cout << '\n';
// Unique requires a sorted list
std::sort ( a.begin(), a.end() );
// Move duplicates to end of list
std::vector<int>::iterator end = std::unique ( a.begin(), a.end() );
// Erase duplicates
a.erase ( end, a.end() );
// Print new contents
std::copy ( a.begin(), a.end(),
std::ostream_iterator<int>(std::cout," "));
std::cout << '\n';
}