Skip to main content
Si fuera C++, unique quita los elementos consecutivos repetidos dentro de un rango (first, last).
Origen Enlace
#include <iostream>
#include <algorithm>
#include <vector>

int main() 
{
    std::vector<int> v{1, 2, 2, 2, 3, 3, 2, 2, 1};
    std::vector<int>::iterator last;

    last = std::unique(v.begin(), v.end()); 
                                        
    for (std::vector<int>::iterator it = v.begin(); it != last; ++it) {
         std::cout << *it << " ";
    }
    std::cout << "\n";
  return 0;
}
#include <iostream>
#include <algorithm>
#include <vector>

int main() 
{
    std::vector<int> v{1, 2, 2, 2, 3, 3, 2, 2, 1};
    std::vector<int>::iterator last;

    last = std::unique(v.begin(), v.end()); 
                                        
    for (std::vector<int>::iterator it = v.begin(); it != last; ++it) {
         std::cout << *it << " ";
    }
    std::cout << "\n";
}
#include <iostream>
#include <algorithm>
#include <vector>

int main() 
{
    std::vector<int> v{1, 2, 2, 2, 3, 3, 2, 2, 1};
    std::vector<int>::iterator last;

    last = std::unique(v.begin(), v.end()); 
                                        
    for (std::vector<int>::iterator it = v.begin(); it != last; ++it) {
         std::cout << *it << " ";
    }
    std::cout << "\n";
  return 0;
}
Origen Enlace

#include <iostream>
#include <algorithm>
#include <vector>

int main() 
{
    std::vector<int> v{1, 2, 2, 2, 3, 3, 2, 2, 1};
    std::vector<int>::iterator last;

    last = std::unique(v.begin(), v.end()); 
                                        
    for (std::vector<int>::iterator it = v.begin(); it != last; ++it) {
         std::cout << *it << " ";
    }
    std::cout << "\n";
}